Trapped-Demo.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
  11. smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[["items"],(function(){
  12. smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
  13. smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[smalltalk.symbolFor("size")]]);
  14. return smalltalk.send(html,"_with_",[" item(s)."]);
  15. })]);
  16. return smalltalk.send(smalltalk.send(html,"_p",[]),"_trapShow_",[[]]);
  17. }),(function(){
  18. return smalltalk.send(html,"_with_",["Loading ..."]);
  19. })]);
  20. return self},
  21. args: ["html"],
  22. 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 p trapShow: #()\x0a ] ifNotPresent: [ html with: 'Loading ...' ]",
  23. messageSends: ["trapShow:", "h2", "trap:toggle:ifNotPresent:", "with:", "span", "p", "div"],
  24. referencedClasses: []
  25. }),
  26. smalltalk.AppView);
  27. smalltalk.addClass('TrappedDumbDispatcher', smalltalk.TrappedDispatcher, ['queue'], 'Trapped-Demo');
  28. smalltalk.addMethod(
  29. "_add_",
  30. smalltalk.method({
  31. selector: "add:",
  32. category: 'accessing',
  33. fn: function (aTriplet){
  34. var self=this;
  35. smalltalk.send(self["@queue"],"_add_",[aTriplet]);
  36. smalltalk.send(self,"_dirty_",[smalltalk.send(aTriplet,"_first",[])]);
  37. return self},
  38. args: ["aTriplet"],
  39. source: "add: aTriplet\x0a\x09queue add: aTriplet.\x0a self dirty: aTriplet first\x0a\x09",
  40. messageSends: ["add:", "dirty:", "first"],
  41. referencedClasses: []
  42. }),
  43. smalltalk.TrappedDumbDispatcher);
  44. smalltalk.addMethod(
  45. "_do_",
  46. smalltalk.method({
  47. selector: "do:",
  48. category: 'enumeration',
  49. fn: function (aBlock){
  50. var self=this;
  51. smalltalk.send(self["@queue"],"_do_",[aBlock]);
  52. return self},
  53. args: ["aBlock"],
  54. source: "do: aBlock\x0a\x09queue do: aBlock",
  55. messageSends: ["do:"],
  56. referencedClasses: []
  57. }),
  58. smalltalk.TrappedDumbDispatcher);
  59. smalltalk.addMethod(
  60. "_initialize",
  61. smalltalk.method({
  62. selector: "initialize",
  63. category: 'initialization',
  64. fn: function (){
  65. var self=this;
  66. self["@queue"]=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
  67. return self},
  68. args: [],
  69. source: "initialize\x0a\x09queue := OrderedCollection new",
  70. messageSends: ["new"],
  71. referencedClasses: ["OrderedCollection"]
  72. }),
  73. smalltalk.TrappedDumbDispatcher);
  74. smalltalk.addClass('TrappedPlainModel', smalltalk.TrappedModelWrapper, [], 'Trapped-Demo');
  75. smalltalk.addMethod(
  76. "_initialize",
  77. smalltalk.method({
  78. selector: "initialize",
  79. category: 'initialization',
  80. fn: function (){
  81. var self=this;
  82. smalltalk.send(self,"_initialize",[],smalltalk.TrappedModelWrapper);
  83. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.TrappedDumbDispatcher || TrappedDumbDispatcher),"_new",[])]);
  84. return self},
  85. args: [],
  86. source: "initialize\x0a\x09super initialize.\x0a self dispatcher: TrappedDumbDispatcher new",
  87. messageSends: ["initialize", "dispatcher:", "new"],
  88. referencedClasses: ["TrappedDumbDispatcher"]
  89. }),
  90. smalltalk.TrappedPlainModel);
  91. smalltalk.addMethod(
  92. "_modify_do_",
  93. smalltalk.method({
  94. selector: "modify:do:",
  95. category: 'action',
  96. fn: function (path,aBlock){
  97. var self=this;
  98. var newValue;
  99. var eavModel;
  100. eavModel=smalltalk.send(path,"_asEavModel",[]);
  101. newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
  102. smalltalk.send((function(){
  103. return smalltalk.send(eavModel,"_on_put_",[smalltalk.send(self,"_payload",[]),newValue]);
  104. }),"_ensure_",[(function(){
  105. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  106. })]);
  107. return self},
  108. args: ["path", "aBlock"],
  109. 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",
  110. messageSends: ["asEavModel", "value:", "on:", "payload", "ensure:", "changed:", "dispatcher", "on:put:"],
  111. referencedClasses: []
  112. }),
  113. smalltalk.TrappedPlainModel);
  114. smalltalk.addMethod(
  115. "_read_do_",
  116. smalltalk.method({
  117. selector: "read:do:",
  118. category: 'action',
  119. fn: function (path,aBlock){
  120. var self=this;
  121. var eavModel;
  122. eavModel=smalltalk.send(path,"_asEavModel",[]);
  123. smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[smalltalk.send(self,"_payload",[])])]);
  124. return self},
  125. args: ["path", "aBlock"],
  126. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: self payload)\x0a",
  127. messageSends: ["asEavModel", "value:", "on:", "payload"],
  128. referencedClasses: []
  129. }),
  130. smalltalk.TrappedPlainModel);
  131. smalltalk.addClass('App', smalltalk.TrappedPlainModel, [], 'Trapped-Demo');
  132. smalltalk.addMethod(
  133. "_initialize",
  134. smalltalk.method({
  135. selector: "initialize",
  136. category: 'initialization',
  137. fn: function (){
  138. var self=this;
  139. smalltalk.send(self,"_initialize",[],smalltalk.TrappedPlainModel);
  140. smalltalk.send(self,"_payload_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("title","__minus_gt",["To-Do List"])])]);
  141. smalltalk.send((function(){
  142. smalltalk.send(smalltalk.send(self,"_payload",[]),"_at_put_",["items",["hello", "world"]]);
  143. return smalltalk.send(self,"_payload_",[smalltalk.send(self,"_payload",[])]);
  144. }),"_valueWithTimeout_",[(2000)]);
  145. return self},
  146. args: [],
  147. 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",
  148. messageSends: ["initialize", "payload:", "->", "valueWithTimeout:", "at:put:", "payload"],
  149. referencedClasses: []
  150. }),
  151. smalltalk.App);