Trapped-Demo.st 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. Smalltalk current createPackage: 'Trapped-Demo' properties: #{}!
  2. Widget subclass: #AppView
  3. instanceVariableNames: ''
  4. package: 'Trapped-Demo'!
  5. !AppView methodsFor: 'rendering'!
  6. renderOn: html
  7. html h2 trapShow: #('title').
  8. html div trap: #('items') toggle: [
  9. html p with: [ html span trapShow: #(#size). html with: ' item(s).' ].
  10. html form with: [ html ul trapIter: #() tag: #li do: [ :each |
  11. html input
  12. type: 'checkbox';
  13. at: 'checked' put: true.
  14. html with: each
  15. ]]
  16. ] ifNotPresent: [ html with: 'Loading ...' ]
  17. ! !
  18. TrappedDispatcher subclass: #TrappedDumbDispatcher
  19. instanceVariableNames: 'queue'
  20. package: 'Trapped-Demo'!
  21. !TrappedDumbDispatcher methodsFor: 'accessing'!
  22. add: aSubscription
  23. queue add: aSubscription.
  24. ! !
  25. !TrappedDumbDispatcher methodsFor: 'bookkeeping'!
  26. clean
  27. queue := queue select: [ :each | each isEnabled ]
  28. ! !
  29. !TrappedDumbDispatcher methodsFor: 'enumeration'!
  30. do: aBlock
  31. queue do: aBlock
  32. ! !
  33. !TrappedDumbDispatcher methodsFor: 'initialization'!
  34. initialize
  35. queue := OrderedCollection new
  36. ! !
  37. TrappedModelWrapper subclass: #TrappedPlainModel
  38. instanceVariableNames: ''
  39. package: 'Trapped-Demo'!
  40. !TrappedPlainModel methodsFor: 'action'!
  41. modify: path do: aBlock
  42. | newValue eavModel |
  43. eavModel := path asEavModel.
  44. newValue := aBlock value: (eavModel on: self payload).
  45. [ eavModel on: self payload put: newValue ] ensure: [ self dispatcher changed: path ]
  46. !
  47. read: path do: aBlock
  48. | eavModel |
  49. eavModel := path asEavModel.
  50. aBlock value: (eavModel on: self payload)
  51. ! !
  52. !TrappedPlainModel methodsFor: 'initialization'!
  53. initialize
  54. super initialize.
  55. self dispatcher: TrappedDumbDispatcher new
  56. ! !
  57. TrappedPlainModel subclass: #App
  58. instanceVariableNames: ''
  59. package: 'Trapped-Demo'!
  60. !App methodsFor: 'initialization'!
  61. initialize
  62. super initialize.
  63. self payload: #{'title' -> 'To-Do List'}.
  64. [ self payload at: 'items' put: #('hello' 'world'). self payload: self payload ] valueWithTimeout: 2000
  65. ! !