Nemo.st 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. Smalltalk current createPackage: 'Nemo' properties: #{}!
  2. Object subclass: #NemoConnection
  3. instanceVariableNames: 'socket'
  4. package: 'Nemo'!
  5. !NemoConnection methodsFor: 'not yet classified'!
  6. close
  7. socket close.
  8. socket := nil
  9. !
  10. createDefaultSocket
  11. self createSocketOn: self defaultURL.
  12. !
  13. createLocalSocketOn: aPort
  14. ^ self createSocketOn: 'ws://localhost:',aPort asString,'/nemo'
  15. !
  16. createSocketOn: uri
  17. socket := <new WebSocket(uri)>.
  18. socket at: 'onmessage' put: [ :message | self handleMessage: message ].
  19. socket at: 'onerror' put: [ :err | console log: err ]
  20. !
  21. defaultURL
  22. ^ self class defaultURL
  23. !
  24. handleMessage: aMessage
  25. | string result |
  26. string := aMessage data.
  27. string isString ifFalse: [ ^ self ].
  28. Transcript show: string.
  29. result := Compiler new evaluateExpression: string.
  30. console log: result.
  31. console log: result asNemoString.
  32. socket send: result asNemoString
  33. !
  34. send: aString
  35. socket send: aString
  36. ! !
  37. NemoConnection class instanceVariableNames: 'default'!
  38. !NemoConnection class methodsFor: 'not yet classified'!
  39. default
  40. ^ default ifNil: [ default := self new ]
  41. !
  42. defaultURL
  43. ^ 'ws://localhost:8010/nemo'
  44. ! !
  45. !Object methodsFor: '*Nemo'!
  46. asNemo
  47. ^ self asJSON
  48. !
  49. asNemoString
  50. ^JSON stringify: self asNemo
  51. ! !
  52. !Class methodsFor: '*Nemo'!
  53. asNemo
  54. ^ Dictionary new
  55. at: 'name' put: self name;
  56. at: 'superclass' put: (self superclass ifNotNil: [ self superclass name ]);
  57. at: 'classComment' put: self comment;
  58. at: 'definition' put: self definition;
  59. at: 'package' put: self category;
  60. asNemo
  61. ! !
  62. !Collection methodsFor: '*Nemo'!
  63. asNemo
  64. ^self asArray collect: [:each | each asNemo]
  65. ! !
  66. !HashedCollection methodsFor: '*Nemo'!
  67. asNemo
  68. | c |
  69. c := self class new.
  70. self keysAndValuesDo: [:key :value |
  71. c at: key put: value asNemo].
  72. ^c
  73. ! !
  74. !Dictionary methodsFor: '*Nemo'!
  75. asNemo
  76. ^self asHashedCollection asNemo
  77. ! !
  78. !String methodsFor: '*Nemo'!
  79. asNemo
  80. ^ self
  81. ! !
  82. !Package methodsFor: '*Nemo'!
  83. asNemo
  84. ^ Dictionary new
  85. at: 'name' put: self name;
  86. asNemo
  87. ! !