Trapped-Demo.st 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. read: path do: aBlock
  32. | data |
  33. data := path asTrapPathOn: self payload.
  34. aBlock value: data.
  35. ! !
  36. !TrappedPlainModel methodsFor: 'initialization'!
  37. initialize
  38. super initialize.
  39. self dispatcher: TrappedDumbDispatcher new
  40. ! !
  41. !TrappedPlainModel class methodsFor: 'action'!
  42. start
  43. self new start
  44. ! !
  45. TrappedPlainModel subclass: #App
  46. instanceVariableNames: ''
  47. package: 'Trapped-Demo'!
  48. !App methodsFor: 'initialization'!
  49. initialize
  50. super initialize.
  51. self payload: #{'items'->#('hello' 'world'). 'title' -> 'To-Do List'}
  52. ! !