Trapped-Demo.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. smalltalk.addPackage('Trapped-Demo', {});
  2. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  3. smalltalk.addMethod(
  4. "_renderOn_",
  5. smalltalk.method({
  6. selector: "renderOn:",
  7. category: 'rendering',
  8. fn: function (html){
  9. var self=this;
  10. var $1,$2;
  11. smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
  12. smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[["items"],(function(){
  13. smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
  14. smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[smalltalk.symbolFor("size")]]);
  15. return smalltalk.send(html,"_with_",[" item(s)."]);
  16. })]);
  17. return smalltalk.send(smalltalk.send(html,"_form",[]),"_with_",[(function(){
  18. return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smalltalk.symbolFor("li"),(function(each){
  19. $1=smalltalk.send(html,"_input",[]);
  20. smalltalk.send($1,"_type_",["checkbox"]);
  21. $2=smalltalk.send($1,"_at_put_",["checked",true]);
  22. $2;
  23. return smalltalk.send(html,"_with_",[each]);
  24. })]);
  25. })]);
  26. }),(function(){
  27. return smalltalk.send(html,"_with_",["Loading ..."]);
  28. })]);
  29. return self},
  30. args: ["html"],
  31. 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 input\x0a type: 'checkbox';\x0a at: 'checked' put: true.\x0a html with: each\x0a ]]\x0a ] ifNotPresent: [ html with: 'Loading ...' ]",
  32. messageSends: ["trapShow:", "h2", "trap:toggle:ifNotPresent:", "with:", "span", "p", "trapIter:tag:do:", "type:", "input", "at:put:", "ul", "form", "div"],
  33. referencedClasses: []
  34. }),
  35. smalltalk.AppView);
  36. smalltalk.addClass('TrappedDumbDispatcher', smalltalk.TrappedDispatcher, ['queue'], 'Trapped-Demo');
  37. smalltalk.addMethod(
  38. "_add_",
  39. smalltalk.method({
  40. selector: "add:",
  41. category: 'accessing',
  42. fn: function (aSubscription){
  43. var self=this;
  44. smalltalk.send(self["@queue"],"_add_",[aSubscription]);
  45. return self},
  46. args: ["aSubscription"],
  47. source: "add: aSubscription\x0a\x09queue add: aSubscription.\x0a",
  48. messageSends: ["add:"],
  49. referencedClasses: []
  50. }),
  51. smalltalk.TrappedDumbDispatcher);
  52. smalltalk.addMethod(
  53. "_clean",
  54. smalltalk.method({
  55. selector: "clean",
  56. category: 'bookkeeping',
  57. fn: function (){
  58. var self=this;
  59. self["@queue"]=smalltalk.send(self["@queue"],"_select_",[(function(each){
  60. return smalltalk.send(each,"_isEnabled",[]);
  61. })]);
  62. return self},
  63. args: [],
  64. source: "clean\x0a\x09queue := queue select: [ :each | each isEnabled ]",
  65. messageSends: ["select:", "isEnabled"],
  66. referencedClasses: []
  67. }),
  68. smalltalk.TrappedDumbDispatcher);
  69. smalltalk.addMethod(
  70. "_do_",
  71. smalltalk.method({
  72. selector: "do:",
  73. category: 'enumeration',
  74. fn: function (aBlock){
  75. var self=this;
  76. smalltalk.send(self["@queue"],"_do_",[aBlock]);
  77. return self},
  78. args: ["aBlock"],
  79. source: "do: aBlock\x0a\x09queue do: aBlock",
  80. messageSends: ["do:"],
  81. referencedClasses: []
  82. }),
  83. smalltalk.TrappedDumbDispatcher);
  84. smalltalk.addMethod(
  85. "_initialize",
  86. smalltalk.method({
  87. selector: "initialize",
  88. category: 'initialization',
  89. fn: function (){
  90. var self=this;
  91. self["@queue"]=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
  92. return self},
  93. args: [],
  94. source: "initialize\x0a\x09queue := OrderedCollection new",
  95. messageSends: ["new"],
  96. referencedClasses: ["OrderedCollection"]
  97. }),
  98. smalltalk.TrappedDumbDispatcher);
  99. smalltalk.addClass('TrappedPlainModel', smalltalk.TrappedModelWrapper, [], 'Trapped-Demo');
  100. smalltalk.addMethod(
  101. "_initialize",
  102. smalltalk.method({
  103. selector: "initialize",
  104. category: 'initialization',
  105. fn: function (){
  106. var self=this;
  107. smalltalk.send(self,"_initialize",[],smalltalk.TrappedModelWrapper);
  108. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.TrappedDumbDispatcher || TrappedDumbDispatcher),"_new",[])]);
  109. return self},
  110. args: [],
  111. source: "initialize\x0a\x09super initialize.\x0a self dispatcher: TrappedDumbDispatcher new",
  112. messageSends: ["initialize", "dispatcher:", "new"],
  113. referencedClasses: ["TrappedDumbDispatcher"]
  114. }),
  115. smalltalk.TrappedPlainModel);
  116. smalltalk.addMethod(
  117. "_modify_do_",
  118. smalltalk.method({
  119. selector: "modify:do:",
  120. category: 'action',
  121. fn: function (path,aBlock){
  122. var self=this;
  123. var newValue;
  124. var eavModel;
  125. eavModel=smalltalk.send(path,"_asEavModel",[]);
  126. newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
  127. smalltalk.send((function(){
  128. return smalltalk.send(eavModel,"_on_put_",[smalltalk.send(self,"_payload",[]),newValue]);
  129. }),"_ensure_",[(function(){
  130. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  131. })]);
  132. return self},
  133. args: ["path", "aBlock"],
  134. source: "modify: path do: aBlock\x0a | newValue eavModel |\x0a eavModel := path asEavModel.\x0a newValue := aBlock value: (eavModel on: self payload).\x0a [ eavModel on: self payload put: newValue ] ensure: [ self dispatcher changed: path ]\x0a",
  135. messageSends: ["asEavModel", "value:", "on:", "payload", "ensure:", "changed:", "dispatcher", "on:put:"],
  136. referencedClasses: []
  137. }),
  138. smalltalk.TrappedPlainModel);
  139. smalltalk.addMethod(
  140. "_read_do_",
  141. smalltalk.method({
  142. selector: "read:do:",
  143. category: 'action',
  144. fn: function (path,aBlock){
  145. var self=this;
  146. var eavModel;
  147. eavModel=smalltalk.send(path,"_asEavModel",[]);
  148. smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
  149. return self},
  150. args: ["path", "aBlock"],
  151. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: self payload)\x0a",
  152. messageSends: ["asEavModel", "value:", "on:", "payload"],
  153. referencedClasses: []
  154. }),
  155. smalltalk.TrappedPlainModel);
  156. smalltalk.addClass('App', smalltalk.TrappedPlainModel, [], 'Trapped-Demo');
  157. smalltalk.addMethod(
  158. "_initialize",
  159. smalltalk.method({
  160. selector: "initialize",
  161. category: 'initialization',
  162. fn: function (){
  163. var self=this;
  164. smalltalk.send(self,"_initialize",[],smalltalk.TrappedPlainModel);
  165. smalltalk.send(self,"_payload_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("title","__minus_gt",["To-Do List"])])]);
  166. smalltalk.send((function(){
  167. smalltalk.send(smalltalk.send(self,"_payload",[]),"_at_put_",["items",["hello", "world"]]);
  168. return smalltalk.send(self,"_payload_",[smalltalk.send(self,"_payload",[])]);
  169. }),"_valueWithTimeout_",[(2000)]);
  170. return self},
  171. args: [],
  172. source: "initialize\x0a\x09super initialize.\x0a\x09self payload: #{'title' -> 'To-Do List'}.\x0a [ self payload at: 'items' put: #('hello' 'world'). self payload: self payload ] valueWithTimeout: 2000\x0a",
  173. messageSends: ["initialize", "payload:", "->", "valueWithTimeout:", "at:put:", "payload"],
  174. referencedClasses: []
  175. }),
  176. smalltalk.App);