Trapped-Demo.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. smalltalk.send(self,"_dirty_",[smalltalk.send(aSubscription,"_isFlagged",[])]);
  46. return self},
  47. args: ["aSubscription"],
  48. source: "add: aSubscription\x0a\x09queue add: aSubscription.\x0a self dirty: aSubscription isFlagged\x0a\x09",
  49. messageSends: ["add:", "dirty:", "isFlagged"],
  50. referencedClasses: []
  51. }),
  52. smalltalk.TrappedDumbDispatcher);
  53. smalltalk.addMethod(
  54. "_clean",
  55. smalltalk.method({
  56. selector: "clean",
  57. category: 'bookkeeping',
  58. fn: function (){
  59. var self=this;
  60. self["@queue"]=smalltalk.send(self["@queue"],"_select_",[(function(each){
  61. return smalltalk.send(each,"_isEnabled",[]);
  62. })]);
  63. return self},
  64. args: [],
  65. source: "clean\x0a\x09queue := queue select: [ :each | each isEnabled ]",
  66. messageSends: ["select:", "isEnabled"],
  67. referencedClasses: []
  68. }),
  69. smalltalk.TrappedDumbDispatcher);
  70. smalltalk.addMethod(
  71. "_do_",
  72. smalltalk.method({
  73. selector: "do:",
  74. category: 'enumeration',
  75. fn: function (aBlock){
  76. var self=this;
  77. smalltalk.send(self["@queue"],"_do_",[aBlock]);
  78. return self},
  79. args: ["aBlock"],
  80. source: "do: aBlock\x0a\x09queue do: aBlock",
  81. messageSends: ["do:"],
  82. referencedClasses: []
  83. }),
  84. smalltalk.TrappedDumbDispatcher);
  85. smalltalk.addMethod(
  86. "_initialize",
  87. smalltalk.method({
  88. selector: "initialize",
  89. category: 'initialization',
  90. fn: function (){
  91. var self=this;
  92. self["@queue"]=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
  93. return self},
  94. args: [],
  95. source: "initialize\x0a\x09queue := OrderedCollection new",
  96. messageSends: ["new"],
  97. referencedClasses: ["OrderedCollection"]
  98. }),
  99. smalltalk.TrappedDumbDispatcher);
  100. smalltalk.addClass('TrappedPlainModel', smalltalk.TrappedModelWrapper, [], 'Trapped-Demo');
  101. smalltalk.addMethod(
  102. "_initialize",
  103. smalltalk.method({
  104. selector: "initialize",
  105. category: 'initialization',
  106. fn: function (){
  107. var self=this;
  108. smalltalk.send(self,"_initialize",[],smalltalk.TrappedModelWrapper);
  109. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.TrappedDumbDispatcher || TrappedDumbDispatcher),"_new",[])]);
  110. return self},
  111. args: [],
  112. source: "initialize\x0a\x09super initialize.\x0a self dispatcher: TrappedDumbDispatcher new",
  113. messageSends: ["initialize", "dispatcher:", "new"],
  114. referencedClasses: ["TrappedDumbDispatcher"]
  115. }),
  116. smalltalk.TrappedPlainModel);
  117. smalltalk.addMethod(
  118. "_modify_do_",
  119. smalltalk.method({
  120. selector: "modify:do:",
  121. category: 'action',
  122. fn: function (path,aBlock){
  123. var self=this;
  124. var newValue;
  125. var eavModel;
  126. eavModel=smalltalk.send(path,"_asEavModel",[]);
  127. newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
  128. smalltalk.send((function(){
  129. return smalltalk.send(eavModel,"_on_put_",[smalltalk.send(self,"_payload",[]),newValue]);
  130. }),"_ensure_",[(function(){
  131. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  132. })]);
  133. return self},
  134. args: ["path", "aBlock"],
  135. 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",
  136. messageSends: ["asEavModel", "value:", "on:", "payload", "ensure:", "changed:", "dispatcher", "on:put:"],
  137. referencedClasses: []
  138. }),
  139. smalltalk.TrappedPlainModel);
  140. smalltalk.addMethod(
  141. "_read_do_",
  142. smalltalk.method({
  143. selector: "read:do:",
  144. category: 'action',
  145. fn: function (path,aBlock){
  146. var self=this;
  147. var eavModel;
  148. eavModel=smalltalk.send(path,"_asEavModel",[]);
  149. smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
  150. return self},
  151. args: ["path", "aBlock"],
  152. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: self payload)\x0a",
  153. messageSends: ["asEavModel", "value:", "on:", "payload"],
  154. referencedClasses: []
  155. }),
  156. smalltalk.TrappedPlainModel);
  157. smalltalk.addClass('App', smalltalk.TrappedPlainModel, [], 'Trapped-Demo');
  158. smalltalk.addMethod(
  159. "_initialize",
  160. smalltalk.method({
  161. selector: "initialize",
  162. category: 'initialization',
  163. fn: function (){
  164. var self=this;
  165. smalltalk.send(self,"_initialize",[],smalltalk.TrappedPlainModel);
  166. smalltalk.send(self,"_payload_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("title","__minus_gt",["To-Do List"])])]);
  167. smalltalk.send((function(){
  168. smalltalk.send(smalltalk.send(self,"_payload",[]),"_at_put_",["items",["hello", "world"]]);
  169. return smalltalk.send(self,"_payload_",[smalltalk.send(self,"_payload",[])]);
  170. }),"_valueWithTimeout_",[(2000)]);
  171. return self},
  172. args: [],
  173. 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",
  174. messageSends: ["initialize", "payload:", "->", "valueWithTimeout:", "at:put:", "payload"],
  175. referencedClasses: []
  176. }),
  177. smalltalk.App);