Trapped-Demo.st 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: aTriplet
  23. queue add: aTriplet.
  24. self dirty: aTriplet first
  25. ! !
  26. !TrappedDumbDispatcher methodsFor: 'bookkeeping'!
  27. clean
  28. queue := queue select: [ :each | each third notNil ]
  29. ! !
  30. !TrappedDumbDispatcher methodsFor: 'enumeration'!
  31. do: aBlock
  32. queue do: aBlock
  33. ! !
  34. !TrappedDumbDispatcher methodsFor: 'initialization'!
  35. initialize
  36. queue := OrderedCollection new
  37. ! !
  38. TrappedModelWrapper subclass: #TrappedPlainModel
  39. instanceVariableNames: ''
  40. package: 'Trapped-Demo'!
  41. !TrappedPlainModel methodsFor: 'action'!
  42. modify: path do: aBlock
  43. | newValue eavModel |
  44. eavModel := path asEavModel.
  45. newValue := aBlock value: (eavModel on: self payload).
  46. [ eavModel on: self payload put: newValue ] ensure: [ self dispatcher changed: path ]
  47. !
  48. read: path do: aBlock
  49. | eavModel |
  50. eavModel := path asEavModel.
  51. aBlock value: (eavModel on: self payload)
  52. ! !
  53. !TrappedPlainModel methodsFor: 'initialization'!
  54. initialize
  55. super initialize.
  56. self dispatcher: TrappedDumbDispatcher new
  57. ! !
  58. TrappedPlainModel subclass: #App
  59. instanceVariableNames: ''
  60. package: 'Trapped-Demo'!
  61. !App methodsFor: 'initialization'!
  62. initialize
  63. super initialize.
  64. self payload: #{'title' -> 'To-Do List'}.
  65. [ self payload at: 'items' put: #('hello' 'world'). self payload: self payload ] valueWithTimeout: 2000
  66. ! !