Trapped-Demo.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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",[]),"_trapShow_",[["items"]]);
  12. return self},
  13. args: ["html"],
  14. source: "renderOn: html\x0a\x09html h2 trapShow: #('title').\x0a\x09html p trapShow: #('items')",
  15. messageSends: ["trapShow:", "h2", "p"],
  16. referencedClasses: []
  17. }),
  18. smalltalk.AppView);
  19. smalltalk.addClass('TrappedDumbDispatcher', smalltalk.TrappedDispatcher, ['queue'], 'Trapped-Demo');
  20. smalltalk.addMethod(
  21. "_add_",
  22. smalltalk.method({
  23. selector: "add:",
  24. category: 'accessing',
  25. fn: function (aTriplet){
  26. var self=this;
  27. smalltalk.send(self["@queue"],"_add_",[aTriplet]);
  28. smalltalk.send(self,"_dirty_",[smalltalk.send(aTriplet,"_first",[])]);
  29. return self},
  30. args: ["aTriplet"],
  31. source: "add: aTriplet\x0a\x09queue add: aTriplet.\x0a self dirty: aTriplet first\x0a\x09",
  32. messageSends: ["add:", "dirty:", "first"],
  33. referencedClasses: []
  34. }),
  35. smalltalk.TrappedDumbDispatcher);
  36. smalltalk.addMethod(
  37. "_do_",
  38. smalltalk.method({
  39. selector: "do:",
  40. category: 'enumeration',
  41. fn: function (aBlock){
  42. var self=this;
  43. smalltalk.send(self["@queue"],"_do_",[aBlock]);
  44. return self},
  45. args: ["aBlock"],
  46. source: "do: aBlock\x0a\x09queue do: aBlock",
  47. messageSends: ["do:"],
  48. referencedClasses: []
  49. }),
  50. smalltalk.TrappedDumbDispatcher);
  51. smalltalk.addMethod(
  52. "_initialize",
  53. smalltalk.method({
  54. selector: "initialize",
  55. category: 'initialization',
  56. fn: function (){
  57. var self=this;
  58. self["@queue"]=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
  59. return self},
  60. args: [],
  61. source: "initialize\x0a\x09queue := OrderedCollection new",
  62. messageSends: ["new"],
  63. referencedClasses: ["OrderedCollection"]
  64. }),
  65. smalltalk.TrappedDumbDispatcher);
  66. smalltalk.addClass('TrappedPlainModel', smalltalk.TrappedModelWrapper, [], 'Trapped-Demo');
  67. smalltalk.addMethod(
  68. "_initialize",
  69. smalltalk.method({
  70. selector: "initialize",
  71. category: 'initialization',
  72. fn: function (){
  73. var self=this;
  74. smalltalk.send(self,"_initialize",[],smalltalk.TrappedModelWrapper);
  75. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.TrappedDumbDispatcher || TrappedDumbDispatcher),"_new",[])]);
  76. return self},
  77. args: [],
  78. source: "initialize\x0a\x09super initialize.\x0a self dispatcher: TrappedDumbDispatcher new",
  79. messageSends: ["initialize", "dispatcher:", "new"],
  80. referencedClasses: ["TrappedDumbDispatcher"]
  81. }),
  82. smalltalk.TrappedPlainModel);
  83. smalltalk.addMethod(
  84. "_read_do_",
  85. smalltalk.method({
  86. selector: "read:do:",
  87. category: 'action',
  88. fn: function (path,aBlock){
  89. var self=this;
  90. var data;
  91. data=smalltalk.send(path,"_inject_into_",[smalltalk.send(self,"_payload",[]),(function(soFar,segment){
  92. return smalltalk.send(soFar,"_at_",[segment]);
  93. })]);
  94. smalltalk.send(aBlock,"_value_",[data]);
  95. return self},
  96. args: ["path", "aBlock"],
  97. source: "read: path do: aBlock\x0a\x09| data |\x0a data := path inject: self payload\x0a \x09into: [ :soFar :segment | soFar at: segment ].\x0a\x09aBlock value: data.",
  98. messageSends: ["inject:into:", "payload", "at:", "value:"],
  99. referencedClasses: []
  100. }),
  101. smalltalk.TrappedPlainModel);
  102. smalltalk.addMethod(
  103. "_start",
  104. smalltalk.method({
  105. selector: "start",
  106. category: 'action',
  107. fn: function (){
  108. var self=this;
  109. smalltalk.send(smalltalk.send(self,"_new",[]),"_start",[]);
  110. return self},
  111. args: [],
  112. source: "start\x0a\x09self new start",
  113. messageSends: ["start", "new"],
  114. referencedClasses: []
  115. }),
  116. smalltalk.TrappedPlainModel.klass);
  117. smalltalk.addClass('App', smalltalk.TrappedPlainModel, [], 'Trapped-Demo');
  118. smalltalk.addMethod(
  119. "_initialize",
  120. smalltalk.method({
  121. selector: "initialize",
  122. category: 'initialization',
  123. fn: function (){
  124. var self=this;
  125. smalltalk.send(self,"_initialize",[],smalltalk.TrappedPlainModel);
  126. smalltalk.send(self,"_payload_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("items","__minus_gt",[["hello", "world"]]),smalltalk.send("title","__minus_gt",["To-Do List"])])]);
  127. return self},
  128. args: [],
  129. source: "initialize\x0a\x09super initialize.\x0a\x09self payload: #{'items'->#('hello' 'world'). 'title' -> 'To-Do List'}",
  130. messageSends: ["initialize", "payload:", "->"],
  131. referencedClasses: []
  132. }),
  133. smalltalk.App);