Trapped-Demo.st 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 p trapShow: #()
  11. ] ifNotPresent: [ html with: 'Loading ...' ]
  12. ! !
  13. TrappedDispatcher subclass: #TrappedDumbDispatcher
  14. instanceVariableNames: 'queue'
  15. package: 'Trapped-Demo'!
  16. !TrappedDumbDispatcher methodsFor: 'accessing'!
  17. add: aTriplet
  18. queue add: aTriplet.
  19. self dirty: aTriplet first
  20. ! !
  21. !TrappedDumbDispatcher methodsFor: 'enumeration'!
  22. do: aBlock
  23. queue do: aBlock
  24. ! !
  25. !TrappedDumbDispatcher methodsFor: 'initialization'!
  26. initialize
  27. queue := OrderedCollection new
  28. ! !
  29. TrappedModelWrapper subclass: #TrappedPlainModel
  30. instanceVariableNames: ''
  31. package: 'Trapped-Demo'!
  32. !TrappedPlainModel methodsFor: 'action'!
  33. modify: path do: aBlock
  34. | newValue eavModel |
  35. eavModel := path asEavModel.
  36. newValue := aBlock value: (eavModel on: self payload).
  37. [ eavModel on: self payload put: newValue ] ensure: [ self dispatcher changed: path ]
  38. !
  39. read: path do: aBlock
  40. | eavModel |
  41. eavModel := path asEavModel.
  42. aBlock value: (eavModel on: self payload)
  43. ! !
  44. !TrappedPlainModel methodsFor: 'initialization'!
  45. initialize
  46. super initialize.
  47. self dispatcher: TrappedDumbDispatcher new
  48. ! !
  49. TrappedPlainModel subclass: #App
  50. instanceVariableNames: ''
  51. package: 'Trapped-Demo'!
  52. !App methodsFor: 'initialization'!
  53. initialize
  54. super initialize.
  55. self payload: #{'title' -> 'To-Do List'}.
  56. [ self payload at: 'items' put: #('hello' 'world'). self payload: self payload ] valueWithTimeout: 2000
  57. ! !