Trapped-Common.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. smalltalk.addPackage('Trapped-Common', {});
  2. smalltalk.addClass('TrappedDispatcher', smalltalk.Object, [], 'Trapped-Common');
  3. smalltalk.TrappedDispatcher.comment="I am base class for change event dispatchers.\x0aI manage changed path - action block subscriptions.\x0aThese subscription must be three-element arrays\x0a\x09{ dirty. path. block }\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09add:\x0a do:\x0a (optionally) run\x0a"
  4. smalltalk.addMethod(
  5. "_changed_",
  6. smalltalk.method({
  7. selector: "changed:",
  8. category: 'action',
  9. fn: function (path){
  10. var self=this;
  11. var $1;
  12. var needsToRun;
  13. needsToRun=false;
  14. smalltalk.send(self,"_do_",[(function(each){
  15. var aPath;
  16. var lesser;
  17. aPath=smalltalk.send(each,"_second",[]);
  18. aPath;
  19. lesser=smalltalk.send(smalltalk.send(aPath,"_size",[]),"_min_",[smalltalk.send(path,"_size",[])]);
  20. lesser;
  21. $1=smalltalk.send(smalltalk.send(path,"_copyFrom_to_",[(1),lesser]),"__eq",[smalltalk.send(aPath,"_copyFrom_to_",[(1),lesser])]);
  22. if(smalltalk.assert($1)){
  23. smalltalk.send(each,"_at_put_",[(1),true]);
  24. needsToRun=true;
  25. return needsToRun;
  26. };
  27. })]);
  28. return needsToRun;
  29. },
  30. args: ["path"],
  31. source: "changed: path\x0a\x09| needsToRun |\x0a needsToRun := false.\x0a\x09self do: [ :each |\x0a\x09\x09| aPath lesser |\x0a\x09\x09aPath := each second.\x0a\x09\x09lesser := aPath size min: path size.\x0a\x09\x09(path copyFrom: 1 to: lesser) = (aPath copyFrom: 1 to: lesser) ifTrue: [\x0a\x09\x09\x09each at: 1 put: true.\x0a needsToRun := true.\x0a\x09\x09]\x0a\x09].\x0a\x09^needsToRun",
  32. messageSends: ["do:", "second", "min:", "size", "ifTrue:", "at:put:", "=", "copyFrom:to:"],
  33. referencedClasses: []
  34. }),
  35. smalltalk.TrappedDispatcher);
  36. smalltalk.addMethod(
  37. "_run",
  38. smalltalk.method({
  39. selector: "run",
  40. category: 'action',
  41. fn: function (){
  42. var self=this;
  43. var $1;
  44. smalltalk.send(self,"_do_",[(function(each){
  45. $1=smalltalk.send(each,"_first",[]);
  46. if(smalltalk.assert($1)){
  47. return smalltalk.send((function(){
  48. return smalltalk.send(smalltalk.send(each,"_third",[]),"_value",[]);
  49. }),"_ensure_",[(function(){
  50. return smalltalk.send(each,"_at_put_",[(1),false]);
  51. })]);
  52. };
  53. })]);
  54. return self},
  55. args: [],
  56. source: "run\x0a\x09self do: [ :each |\x0a\x09\x09each first ifTrue: [[ each third value ] ensure: [ each at: 1 put: false ]]\x0a\x09]",
  57. messageSends: ["do:", "ifTrue:", "ensure:", "at:put:", "value", "third", "first"],
  58. referencedClasses: []
  59. }),
  60. smalltalk.TrappedDispatcher);
  61. smalltalk.addClass('TrappedModelWrapper', smalltalk.Object, ['dispatcher', 'payload'], 'Trapped-Common');
  62. smalltalk.TrappedModelWrapper.comment="I am base class for model wrappers.\x0aI wrap a model which can be any object.\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09read:do:\x0a\x09(optionally) name\x0a\x0aand must initialize:\x0a\x09payload\x0a\x09dispatcher\x0a"
  63. smalltalk.addMethod(
  64. "_dispatcher",
  65. smalltalk.method({
  66. selector: "dispatcher",
  67. category: 'accessing',
  68. fn: function (){
  69. var self=this;
  70. return self["@dispatcher"];
  71. },
  72. args: [],
  73. source: "dispatcher\x0a\x09^dispatcher",
  74. messageSends: [],
  75. referencedClasses: []
  76. }),
  77. smalltalk.TrappedModelWrapper);
  78. smalltalk.addMethod(
  79. "_dispatcher_",
  80. smalltalk.method({
  81. selector: "dispatcher:",
  82. category: 'accessing',
  83. fn: function (aDispatcher){
  84. var self=this;
  85. self["@dispatcher"]=aDispatcher;
  86. return self},
  87. args: ["aDispatcher"],
  88. source: "dispatcher: aDispatcher\x0a\x09dispatcher := aDispatcher",
  89. messageSends: [],
  90. referencedClasses: []
  91. }),
  92. smalltalk.TrappedModelWrapper);
  93. smalltalk.addMethod(
  94. "_name",
  95. smalltalk.method({
  96. selector: "name",
  97. category: 'accessing',
  98. fn: function (){
  99. var self=this;
  100. var $1;
  101. $1=smalltalk.send(smalltalk.send(self,"_class",[]),"_name",[]);
  102. return $1;
  103. },
  104. args: [],
  105. source: "name\x0a\x09^ self class name",
  106. messageSends: ["name", "class"],
  107. referencedClasses: []
  108. }),
  109. smalltalk.TrappedModelWrapper);
  110. smalltalk.addMethod(
  111. "_payload",
  112. smalltalk.method({
  113. selector: "payload",
  114. category: 'accessing',
  115. fn: function (){
  116. var self=this;
  117. return self["@payload"];
  118. },
  119. args: [],
  120. source: "payload\x0a\x09^payload",
  121. messageSends: [],
  122. referencedClasses: []
  123. }),
  124. smalltalk.TrappedModelWrapper);
  125. smalltalk.addMethod(
  126. "_payload_",
  127. smalltalk.method({
  128. selector: "payload:",
  129. category: 'accessing',
  130. fn: function (anObject){
  131. var self=this;
  132. self["@payload"]=anObject;
  133. return self},
  134. args: ["anObject"],
  135. source: "payload: anObject\x0a\x09payload := anObject",
  136. messageSends: [],
  137. referencedClasses: []
  138. }),
  139. smalltalk.TrappedModelWrapper);
  140. smalltalk.addMethod(
  141. "_start",
  142. smalltalk.method({
  143. selector: "start",
  144. category: 'action',
  145. fn: function (){
  146. var self=this;
  147. smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_register_name_",[self,smalltalk.send(self,"_name",[])]);
  148. return self},
  149. args: [],
  150. source: "start\x0a\x09Trapped current register: self name: self name",
  151. messageSends: ["register:name:", "name", "current"],
  152. referencedClasses: ["Trapped"]
  153. }),
  154. smalltalk.TrappedModelWrapper);
  155. smalltalk.addMethod(
  156. "_watch_do_",
  157. smalltalk.method({
  158. selector: "watch:do:",
  159. category: 'action',
  160. fn: function (path,aBlock){
  161. var self=this;
  162. smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_add_",[[true,path,(function(){
  163. return smalltalk.send(self,"_read_do_",[path,aBlock]);
  164. })]]);
  165. smalltalk.send((function(){
  166. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_run",[]);
  167. }),"_fork",[]);
  168. return self},
  169. args: ["path", "aBlock"],
  170. source: "watch: path do: aBlock\x0a\x09self dispatcher add: { true. path. [ self read: path do: aBlock ] }.\x0a [ self dispatcher run ] fork",
  171. messageSends: ["add:", "read:do:", "dispatcher", "fork", "run"],
  172. referencedClasses: []
  173. }),
  174. smalltalk.TrappedModelWrapper);
  175. smalltalk.addMethod(
  176. "_start",
  177. smalltalk.method({
  178. selector: "start",
  179. category: 'action',
  180. fn: function (){
  181. var self=this;
  182. smalltalk.send(smalltalk.send(self,"_new",[]),"_start",[]);
  183. return self},
  184. args: [],
  185. source: "start\x0a\x09self new start",
  186. messageSends: ["start", "new"],
  187. referencedClasses: []
  188. }),
  189. smalltalk.TrappedModelWrapper.klass);