Trapped-Demo.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. smalltalk.addPackage('Trapped-Demo', {});
  2. smalltalk.addClass('App', smalltalk.TrappedMWIsolated, [], 'Trapped-Demo');
  3. smalltalk.addMethod(
  4. "_initialize",
  5. smalltalk.method({
  6. selector: "initialize",
  7. category: 'initialization',
  8. fn: function (){
  9. var self=this;
  10. var obj;
  11. smalltalk.send(self,"_initialize",[],smalltalk.TrappedMWIsolated);
  12. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.TrappedDumbDispatcher || TrappedDumbDispatcher),"_new",[])]);
  13. obj=smalltalk.HashedCollection._fromPairs_([smalltalk.send("title","__minus_gt",["To-Do List"])]);
  14. smalltalk.send(self,"_model_",[obj]);
  15. smalltalk.send((function(){
  16. smalltalk.send(obj,"_at_put_",["items",[[true, "hello"], [false, "world"]]]);
  17. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[[]]);
  18. }),"_valueWithTimeout_",[(2000)]);
  19. return self},
  20. args: [],
  21. source: "initialize\x0a\x09| obj |\x0a\x09super initialize.\x0a self dispatcher: TrappedDumbDispatcher new.\x0a obj := #{'title' -> 'To-Do List'}.\x0a self model: obj.\x0a [ obj at: 'items' put: #(#(true 'hello') #(false 'world')). self dispatcher changed: #() ] valueWithTimeout: 2000\x0a",
  22. messageSends: ["initialize", "dispatcher:", "new", "->", "model:", "valueWithTimeout:", "at:put:", "changed:", "dispatcher"],
  23. referencedClasses: ["TrappedDumbDispatcher"]
  24. }),
  25. smalltalk.App);
  26. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  27. smalltalk.addMethod(
  28. "_renderOn_",
  29. smalltalk.method({
  30. selector: "renderOn:",
  31. category: 'rendering',
  32. fn: function (html){
  33. var self=this;
  34. var $1,$2,$3,$4;
  35. smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
  36. smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[["items"],(function(){
  37. smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
  38. smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[smalltalk.symbolFor("size")]]);
  39. return smalltalk.send(html,"_with_",[" item(s)."]);
  40. })]);
  41. smalltalk.send(smalltalk.send(html,"_form",[]),"_with_",[(function(){
  42. return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smalltalk.symbolFor("li"),(function(each){
  43. smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
  44. $1=smalltalk.send(html,"_input",[]);
  45. smalltalk.send($1,"_type_",["checkbox"]);
  46. $2=smalltalk.send($1,"_trapBind_",[[(1)]]);
  47. $2;
  48. return smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[(2)]]);
  49. })]);
  50. })]);
  51. smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",["... and again, to see the bidirectional binding:"]);
  52. return smalltalk.send(smalltalk.send(html,"_form",[]),"_with_",[(function(){
  53. return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smalltalk.symbolFor("li"),(function(each){
  54. smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
  55. $3=smalltalk.send(html,"_input",[]);
  56. smalltalk.send($3,"_type_",["checkbox"]);
  57. $4=smalltalk.send($3,"_trapBind_",[[(1)]]);
  58. $4;
  59. return smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[(2)]]);
  60. })]);
  61. })]);
  62. }),(function(){
  63. return smalltalk.send(html,"_with_",["Loading ..."]);
  64. })]);
  65. return self},
  66. args: ["html"],
  67. source: "renderOn: html\x0a\x09html h2 trapShow: #('title').\x0a html div trap: #('items') toggle: [\x0a html p with: [ html span trapShow: #(#size). html with: ' item(s).' ].\x0a\x09\x09html form with: [ html ul trapIter: #() tag: #li do: [ :each |\x0a html root empty.\x0a html input\x0a type: 'checkbox';\x0a trapBind: #(1).\x0a html span trapShow: #(2).\x0a ]].\x0a html p with: '... and again, to see the bidirectional binding:'.\x0a\x09\x09html form with: [ html ul trapIter: #() tag: #li do: [ :each |\x0a html root empty.\x0a html input\x0a type: 'checkbox';\x0a trapBind: #(1).\x0a html span trapShow: #(2).\x0a ]].\x0a ] ifNotPresent: [ html with: 'Loading ...' ]",
  68. messageSends: ["trapShow:", "h2", "trap:toggle:ifNotPresent:", "with:", "span", "p", "trapIter:tag:do:", "empty", "root", "type:", "input", "trapBind:", "ul", "form", "div"],
  69. referencedClasses: []
  70. }),
  71. smalltalk.AppView);
  72. smalltalk.addClass('TrappedDumbDispatcher', smalltalk.TrappedDispatcher, ['queue'], 'Trapped-Demo');
  73. smalltalk.addMethod(
  74. "_add_",
  75. smalltalk.method({
  76. selector: "add:",
  77. category: 'accessing',
  78. fn: function (aSubscription){
  79. var self=this;
  80. smalltalk.send(self["@queue"],"_add_",[aSubscription]);
  81. return self},
  82. args: ["aSubscription"],
  83. source: "add: aSubscription\x0a\x09queue add: aSubscription.\x0a",
  84. messageSends: ["add:"],
  85. referencedClasses: []
  86. }),
  87. smalltalk.TrappedDumbDispatcher);
  88. smalltalk.addMethod(
  89. "_clean",
  90. smalltalk.method({
  91. selector: "clean",
  92. category: 'bookkeeping',
  93. fn: function (){
  94. var self=this;
  95. self["@queue"]=smalltalk.send(self["@queue"],"_select_",[(function(each){
  96. return smalltalk.send(each,"_isEnabled",[]);
  97. })]);
  98. return self},
  99. args: [],
  100. source: "clean\x0a\x09queue := queue select: [ :each | each isEnabled ]",
  101. messageSends: ["select:", "isEnabled"],
  102. referencedClasses: []
  103. }),
  104. smalltalk.TrappedDumbDispatcher);
  105. smalltalk.addMethod(
  106. "_do_",
  107. smalltalk.method({
  108. selector: "do:",
  109. category: 'enumeration',
  110. fn: function (aBlock){
  111. var self=this;
  112. smalltalk.send(self["@queue"],"_do_",[aBlock]);
  113. return self},
  114. args: ["aBlock"],
  115. source: "do: aBlock\x0a\x09queue do: aBlock",
  116. messageSends: ["do:"],
  117. referencedClasses: []
  118. }),
  119. smalltalk.TrappedDumbDispatcher);
  120. smalltalk.addMethod(
  121. "_initialize",
  122. smalltalk.method({
  123. selector: "initialize",
  124. category: 'initialization',
  125. fn: function (){
  126. var self=this;
  127. self["@queue"]=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
  128. return self},
  129. args: [],
  130. source: "initialize\x0a\x09queue := OrderedCollection new",
  131. messageSends: ["new"],
  132. referencedClasses: ["OrderedCollection"]
  133. }),
  134. smalltalk.TrappedDumbDispatcher);