Trapped-Demo.st 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Smalltalk current createPackage: 'Trapped-Demo' properties: #{}!
  2. TrappedMWIsolated subclass: #App
  3. instanceVariableNames: ''
  4. package: 'Trapped-Demo'!
  5. !App methodsFor: 'initialization'!
  6. initialize
  7. | obj |
  8. super initialize.
  9. self dispatcher: TrappedDumbDispatcher new.
  10. obj := #{'title' -> 'To-Do List'}.
  11. self model: obj.
  12. [ obj at: 'items' put: #(#(true 'hello') #(false 'world')). self dispatcher changed: #() ] valueWithTimeout: 2000
  13. ! !
  14. Widget subclass: #AppView
  15. instanceVariableNames: ''
  16. package: 'Trapped-Demo'!
  17. !AppView methodsFor: 'rendering'!
  18. renderOn: html
  19. html h2 trapShow: #('title').
  20. html div trap: #('items') toggle: [
  21. html p with: [ html span trapShow: #(#size). html with: ' item(s).' ].
  22. html form with: [ html ul trapIter: #() tag: #li do: [ :each |
  23. html root empty.
  24. html input
  25. type: 'checkbox';
  26. trapBind: #(1).
  27. html span trapShow: #(2).
  28. ]].
  29. html p with: '... and again, to see the bidirectional binding:'.
  30. html form with: [ html ul trapIter: #() tag: #li do: [ :each |
  31. html root empty.
  32. html input
  33. type: 'checkbox';
  34. trapBind: #(1).
  35. html span trapShow: #(2).
  36. ]].
  37. ] ifNotPresent: [ html with: 'Loading ...' ]
  38. ! !
  39. TrappedDispatcher subclass: #TrappedDumbDispatcher
  40. instanceVariableNames: 'queue'
  41. package: 'Trapped-Demo'!
  42. !TrappedDumbDispatcher methodsFor: 'accessing'!
  43. add: aSubscription
  44. queue add: aSubscription.
  45. ! !
  46. !TrappedDumbDispatcher methodsFor: 'bookkeeping'!
  47. clean
  48. queue := queue select: [ :each | each isEnabled ]
  49. ! !
  50. !TrappedDumbDispatcher methodsFor: 'enumeration'!
  51. do: aBlock
  52. queue do: aBlock
  53. ! !
  54. !TrappedDumbDispatcher methodsFor: 'initialization'!
  55. initialize
  56. queue := OrderedCollection new
  57. ! !