Trapped-Demo.js 5.5 KB

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