Trapped-Demo.st 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: #('hello' '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 input
  24. type: 'checkbox';
  25. at: 'checked' put: true.
  26. html with: each
  27. ]]
  28. ] ifNotPresent: [ html with: 'Loading ...' ]
  29. ! !
  30. TrappedDispatcher subclass: #TrappedDumbDispatcher
  31. instanceVariableNames: 'queue'
  32. package: 'Trapped-Demo'!
  33. !TrappedDumbDispatcher methodsFor: 'accessing'!
  34. add: aSubscription
  35. queue add: aSubscription.
  36. ! !
  37. !TrappedDumbDispatcher methodsFor: 'bookkeeping'!
  38. clean
  39. queue := queue select: [ :each | each isEnabled ]
  40. ! !
  41. !TrappedDumbDispatcher methodsFor: 'enumeration'!
  42. do: aBlock
  43. queue do: aBlock
  44. ! !
  45. !TrappedDumbDispatcher methodsFor: 'initialization'!
  46. initialize
  47. queue := OrderedCollection new
  48. ! !