Trapped-Demo.st 1.7 KB

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