Trapped-Backend.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. define("trapped/Trapped-Backend", ["amber/boot"
  2. //>>excludeStart("imports", pragmas.excludeImports);
  3. , "lyst/Lyst"
  4. //>>excludeEnd("imports");
  5. , "amber_core/Kernel-Objects", "axon/Axon", "amber_core/Kernel-Collections"], function($boot
  6. //>>excludeStart("imports", pragmas.excludeImports);
  7. //>>excludeEnd("imports");
  8. ){"use strict";
  9. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  10. $core.addPackage('Trapped-Backend');
  11. $core.packages["Trapped-Backend"].innerEval = function (expr) { return eval(expr); };
  12. $core.packages["Trapped-Backend"].imports = ["lyst/Lyst"];
  13. $core.packages["Trapped-Backend"].transport = {"type":"amd","amdNamespace":"trapped"};
  14. $core.addClass('EavModel', $globals.Object, ['getBlock', 'putBlock'], 'Trapped-Backend');
  15. //>>excludeStart("ide", pragmas.excludeIdeData);
  16. $globals.EavModel.comment="External actor value model.";
  17. //>>excludeEnd("ide");
  18. $core.addMethod(
  19. $core.method({
  20. selector: "getBlock:",
  21. protocol: 'accessing',
  22. fn: function (aBlock){
  23. var self=this;
  24. self["@getBlock"]=aBlock;
  25. return self;
  26. },
  27. //>>excludeStart("ide", pragmas.excludeIdeData);
  28. args: ["aBlock"],
  29. source: "getBlock: aBlock\x0a\x0agetBlock := aBlock",
  30. referencedClasses: [],
  31. //>>excludeEnd("ide");
  32. messageSends: []
  33. }),
  34. $globals.EavModel);
  35. $core.addMethod(
  36. $core.method({
  37. selector: "initialize",
  38. protocol: 'initialization',
  39. fn: function (){
  40. var self=this;
  41. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  42. return $core.withContext(function($ctx1) {
  43. //>>excludeEnd("ctx");
  44. (
  45. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  46. $ctx1.supercall = true,
  47. //>>excludeEnd("ctx");
  48. $globals.EavModel.superclass.fn.prototype._initialize.apply($recv(self), []));
  49. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  50. $ctx1.supercall = false;
  51. //>>excludeEnd("ctx");;
  52. self["@getBlock"]=(function(){
  53. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  54. return $core.withContext(function($ctx2) {
  55. //>>excludeEnd("ctx");
  56. return self._error_("No getter block.");
  57. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  58. $ctx2.sendIdx["error:"]=1;
  59. //>>excludeEnd("ctx");
  60. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  61. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  62. //>>excludeEnd("ctx");
  63. });
  64. self["@putBlock"]=(function(){
  65. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  66. return $core.withContext(function($ctx2) {
  67. //>>excludeEnd("ctx");
  68. return self._error_("No putter block.");
  69. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  70. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  71. //>>excludeEnd("ctx");
  72. });
  73. return self;
  74. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  75. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.EavModel)});
  76. //>>excludeEnd("ctx");
  77. },
  78. //>>excludeStart("ide", pragmas.excludeIdeData);
  79. args: [],
  80. source: "initialize\x0a\x09super initialize.\x0a\x09getBlock := [ self error: 'No getter block.' ].\x0a\x09putBlock := [ self error: 'No putter block.' ].",
  81. referencedClasses: [],
  82. //>>excludeEnd("ide");
  83. messageSends: ["initialize", "error:"]
  84. }),
  85. $globals.EavModel);
  86. $core.addMethod(
  87. $core.method({
  88. selector: "on:",
  89. protocol: 'accessing',
  90. fn: function (anObject){
  91. var self=this;
  92. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  93. return $core.withContext(function($ctx1) {
  94. //>>excludeEnd("ctx");
  95. var $1;
  96. $1=$recv(self["@getBlock"])._value_(anObject);
  97. return $1;
  98. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  99. }, function($ctx1) {$ctx1.fill(self,"on:",{anObject:anObject},$globals.EavModel)});
  100. //>>excludeEnd("ctx");
  101. },
  102. //>>excludeStart("ide", pragmas.excludeIdeData);
  103. args: ["anObject"],
  104. source: "on: anObject\x0a\x22Returns value of model applied on object\x22\x0a\x0a^getBlock value: anObject",
  105. referencedClasses: [],
  106. //>>excludeEnd("ide");
  107. messageSends: ["value:"]
  108. }),
  109. $globals.EavModel);
  110. $core.addMethod(
  111. $core.method({
  112. selector: "on:put:",
  113. protocol: 'accessing',
  114. fn: function (anObject,anObject2){
  115. var self=this;
  116. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  117. return $core.withContext(function($ctx1) {
  118. //>>excludeEnd("ctx");
  119. var $1;
  120. $1=$recv(self["@putBlock"])._value_value_(anObject,anObject2);
  121. return $1;
  122. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  123. }, function($ctx1) {$ctx1.fill(self,"on:put:",{anObject:anObject,anObject2:anObject2},$globals.EavModel)});
  124. //>>excludeEnd("ctx");
  125. },
  126. //>>excludeStart("ide", pragmas.excludeIdeData);
  127. args: ["anObject", "anObject2"],
  128. source: "on: anObject put: anObject2\x0a\x22Puts a value via model applied on object\x22\x0a\x0a^putBlock value: anObject value: anObject2",
  129. referencedClasses: [],
  130. //>>excludeEnd("ide");
  131. messageSends: ["value:value:"]
  132. }),
  133. $globals.EavModel);
  134. $core.addMethod(
  135. $core.method({
  136. selector: "putBlock:",
  137. protocol: 'accessing',
  138. fn: function (aBlock){
  139. var self=this;
  140. self["@putBlock"]=aBlock;
  141. return self;
  142. },
  143. //>>excludeStart("ide", pragmas.excludeIdeData);
  144. args: ["aBlock"],
  145. source: "putBlock: aBlock\x0a\x0aputBlock := aBlock",
  146. referencedClasses: [],
  147. //>>excludeEnd("ide");
  148. messageSends: []
  149. }),
  150. $globals.EavModel);
  151. $core.addClass('InterestedInTrapPath', $globals.AxonInterestBase, [], 'Trapped-Backend');
  152. $core.addMethod(
  153. $core.method({
  154. selector: "accepts:",
  155. protocol: 'testing',
  156. fn: function (anAspect){
  157. var self=this;
  158. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  159. return $core.withContext(function($ctx1) {
  160. //>>excludeEnd("ctx");
  161. var $3,$4,$2,$1;
  162. $3=$recv(anAspect)._size();
  163. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  164. $ctx1.sendIdx["size"]=1;
  165. //>>excludeEnd("ctx");
  166. $4=$recv(self["@aspect"])._size();
  167. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  168. $ctx1.sendIdx["size"]=2;
  169. //>>excludeEnd("ctx");
  170. $2=$recv($3).__lt_eq($4);
  171. $1=$recv($2)._and_((function(){
  172. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  173. return $core.withContext(function($ctx2) {
  174. //>>excludeEnd("ctx");
  175. return $recv(anAspect).__eq($recv(self["@aspect"])._copyFrom_to_((1),$recv(anAspect)._size()));
  176. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  177. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  178. //>>excludeEnd("ctx");
  179. }));
  180. return $1;
  181. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  182. }, function($ctx1) {$ctx1.fill(self,"accepts:",{anAspect:anAspect},$globals.InterestedInTrapPath)});
  183. //>>excludeEnd("ctx");
  184. },
  185. //>>excludeStart("ide", pragmas.excludeIdeData);
  186. args: ["anAspect"],
  187. source: "accepts: anAspect\x0a ^anAspect size <= aspect size and: [anAspect = (aspect copyFrom: 1 to: anAspect size)]",
  188. referencedClasses: [],
  189. //>>excludeEnd("ide");
  190. messageSends: ["and:", "<=", "size", "=", "copyFrom:to:"]
  191. }),
  192. $globals.InterestedInTrapPath);
  193. $core.addClass('InterestedInTrapPathSubtree', $globals.AxonInterestBase, [], 'Trapped-Backend');
  194. $core.addMethod(
  195. $core.method({
  196. selector: "accepts:",
  197. protocol: 'testing',
  198. fn: function (anAspect){
  199. var self=this;
  200. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  201. return $core.withContext(function($ctx1) {
  202. //>>excludeEnd("ctx");
  203. var $3,$4,$2,$6,$7,$5,$1;
  204. $3=$recv(anAspect)._size();
  205. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  206. $ctx1.sendIdx["size"]=1;
  207. //>>excludeEnd("ctx");
  208. $4=$recv(self["@aspect"])._size();
  209. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  210. $ctx1.sendIdx["size"]=2;
  211. //>>excludeEnd("ctx");
  212. $2=$recv($3).__lt_eq($4);
  213. if($core.assert($2)){
  214. $6=self["@aspect"];
  215. $7=$recv(anAspect)._size();
  216. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  217. $ctx1.sendIdx["size"]=3;
  218. //>>excludeEnd("ctx");
  219. $5=$recv($6)._copyFrom_to_((1),$7);
  220. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  221. $ctx1.sendIdx["copyFrom:to:"]=1;
  222. //>>excludeEnd("ctx");
  223. $1=$recv(anAspect).__eq($5);
  224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  225. $ctx1.sendIdx["="]=1;
  226. //>>excludeEnd("ctx");
  227. } else {
  228. $1=$recv(self["@aspect"]).__eq($recv(anAspect)._copyFrom_to_((1),$recv(self["@aspect"])._size()));
  229. };
  230. return $1;
  231. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  232. }, function($ctx1) {$ctx1.fill(self,"accepts:",{anAspect:anAspect},$globals.InterestedInTrapPathSubtree)});
  233. //>>excludeEnd("ctx");
  234. },
  235. //>>excludeStart("ide", pragmas.excludeIdeData);
  236. args: ["anAspect"],
  237. source: "accepts: anAspect\x0a ^anAspect size <= aspect size\x0a\x09\x09ifTrue: [anAspect = (aspect copyFrom: 1 to: anAspect size)]\x0a\x09\x09ifFalse: [aspect = (anAspect copyFrom: 1 to: aspect size)]",
  238. referencedClasses: [],
  239. //>>excludeEnd("ide");
  240. messageSends: ["ifTrue:ifFalse:", "<=", "size", "=", "copyFrom:to:"]
  241. }),
  242. $globals.InterestedInTrapPathSubtree);
  243. $core.addClass('Isolator', $globals.Object, ['root'], 'Trapped-Backend');
  244. $core.addMethod(
  245. $core.method({
  246. selector: "model:modify:",
  247. protocol: 'action',
  248. fn: function (anEavModel,aBlock){
  249. var self=this;
  250. var newValue;
  251. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  252. return $core.withContext(function($ctx1) {
  253. //>>excludeEnd("ctx");
  254. newValue=$recv(aBlock)._value_($recv(anEavModel)._on_(self));
  255. $recv(anEavModel)._on_put_(self,$recv(newValue)._deepCopy());
  256. return self;
  257. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  258. }, function($ctx1) {$ctx1.fill(self,"model:modify:",{anEavModel:anEavModel,aBlock:aBlock,newValue:newValue},$globals.Isolator)});
  259. //>>excludeEnd("ctx");
  260. },
  261. //>>excludeStart("ide", pragmas.excludeIdeData);
  262. args: ["anEavModel", "aBlock"],
  263. source: "model: anEavModel modify: aBlock\x0a\x0a| newValue |\x0anewValue := aBlock value: (anEavModel on: self).\x0aanEavModel on: self put: newValue deepCopy",
  264. referencedClasses: [],
  265. //>>excludeEnd("ide");
  266. messageSends: ["value:", "on:", "on:put:", "deepCopy"]
  267. }),
  268. $globals.Isolator);
  269. $core.addMethod(
  270. $core.method({
  271. selector: "model:read:",
  272. protocol: 'action',
  273. fn: function (anEavModel,aBlock){
  274. var self=this;
  275. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  276. return $core.withContext(function($ctx1) {
  277. //>>excludeEnd("ctx");
  278. $recv(aBlock)._value_($recv($recv(anEavModel)._on_(self))._deepCopy());
  279. return self;
  280. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  281. }, function($ctx1) {$ctx1.fill(self,"model:read:",{anEavModel:anEavModel,aBlock:aBlock},$globals.Isolator)});
  282. //>>excludeEnd("ctx");
  283. },
  284. //>>excludeStart("ide", pragmas.excludeIdeData);
  285. args: ["anEavModel", "aBlock"],
  286. source: "model: anEavModel read: aBlock\x0a\x0aaBlock value: (anEavModel on: self) deepCopy",
  287. referencedClasses: [],
  288. //>>excludeEnd("ide");
  289. messageSends: ["value:", "deepCopy", "on:"]
  290. }),
  291. $globals.Isolator);
  292. $core.addMethod(
  293. $core.method({
  294. selector: "root",
  295. protocol: 'accessing',
  296. fn: function (){
  297. var self=this;
  298. var $1;
  299. $1=self["@root"];
  300. return $1;
  301. },
  302. //>>excludeStart("ide", pragmas.excludeIdeData);
  303. args: [],
  304. source: "root\x0a\x0a^root",
  305. referencedClasses: [],
  306. //>>excludeEnd("ide");
  307. messageSends: []
  308. }),
  309. $globals.Isolator);
  310. $core.addMethod(
  311. $core.method({
  312. selector: "root:",
  313. protocol: 'accessing',
  314. fn: function (anObject){
  315. var self=this;
  316. self["@root"]=anObject;
  317. return self;
  318. },
  319. //>>excludeStart("ide", pragmas.excludeIdeData);
  320. args: ["anObject"],
  321. source: "root: anObject\x0a\x0aroot := anObject",
  322. referencedClasses: [],
  323. //>>excludeEnd("ide");
  324. messageSends: []
  325. }),
  326. $globals.Isolator);
  327. $core.addMethod(
  328. $core.method({
  329. selector: "on:",
  330. protocol: 'instance creation',
  331. fn: function (anObject){
  332. var self=this;
  333. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  334. return $core.withContext(function($ctx1) {
  335. //>>excludeEnd("ctx");
  336. var $1;
  337. $1=$recv(self._new())._root_(anObject);
  338. return $1;
  339. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  340. }, function($ctx1) {$ctx1.fill(self,"on:",{anObject:anObject},$globals.Isolator.klass)});
  341. //>>excludeEnd("ctx");
  342. },
  343. //>>excludeStart("ide", pragmas.excludeIdeData);
  344. args: ["anObject"],
  345. source: "on: anObject\x0a^self new root: anObject",
  346. referencedClasses: [],
  347. //>>excludeEnd("ide");
  348. messageSends: ["root:", "new"]
  349. }),
  350. $globals.Isolator.klass);
  351. $core.addClass('Trapper', $globals.AxonizedObject, ['payload'], 'Trapped-Backend');
  352. //>>excludeStart("ide", pragmas.excludeIdeData);
  353. $globals.Trapper.comment="A portmanteau of 'Trapped wrapper', I am base class for model objects wrapped by Trapped.\x0a\x0aWrapped object is indexed by #('string-at-index' #selector numeric-at-index) array paths. Operations using this indexing are:\x0a\x0a - `read:do` to get the indexed content\x0a - `modify:do:` to get and modify the indexed content, and\x0a - `watch:do:` to subscribe to changes of the indexed content.\x0a\x0aThe wrapped model can be any smalltalk object.\x0a\x0aMy subclasses need to provide implementation for:\x0a\x0a - read:do:\x0a - modify:do:\x0a\x0aand must issue these calls when initializing:\x0a\x0a - axon: (with a subclass of `AxonBase`)\x0a - model: (with a wrapped object, after `axon:`)";
  354. //>>excludeEnd("ide");
  355. $core.addMethod(
  356. $core.method({
  357. selector: "interestOn:block:",
  358. protocol: 'action',
  359. fn: function (anAspect,aBlock){
  360. var self=this;
  361. function $InterestedInTrapPathSubtree(){return $globals.InterestedInTrapPathSubtree||(typeof InterestedInTrapPathSubtree=="undefined"?nil:InterestedInTrapPathSubtree)}
  362. function $InterestedInTrapPath(){return $globals.InterestedInTrapPath||(typeof InterestedInTrapPath=="undefined"?nil:InterestedInTrapPath)}
  363. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  364. return $core.withContext(function($ctx1) {
  365. //>>excludeEnd("ctx");
  366. var $1,$3,$2,$4;
  367. $1=$recv($recv(anAspect)._notEmpty())._and_((function(){
  368. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  369. return $core.withContext(function($ctx2) {
  370. //>>excludeEnd("ctx");
  371. return $recv($recv(anAspect)._last())._isNil();
  372. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  373. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  374. //>>excludeEnd("ctx");
  375. }));
  376. if($core.assert($1)){
  377. $3=$recv($InterestedInTrapPathSubtree())._new();
  378. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  379. $ctx1.sendIdx["new"]=1;
  380. //>>excludeEnd("ctx");
  381. $2=$recv($3)._aspect_block_($recv(anAspect)._allButLast(),aBlock);
  382. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  383. $ctx1.sendIdx["aspect:block:"]=1;
  384. //>>excludeEnd("ctx");
  385. return $2;
  386. } else {
  387. $4=$recv($recv($InterestedInTrapPath())._new())._aspect_block_(anAspect,aBlock);
  388. return $4;
  389. };
  390. return self;
  391. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  392. }, function($ctx1) {$ctx1.fill(self,"interestOn:block:",{anAspect:anAspect,aBlock:aBlock},$globals.Trapper)});
  393. //>>excludeEnd("ctx");
  394. },
  395. //>>excludeStart("ide", pragmas.excludeIdeData);
  396. args: ["anAspect", "aBlock"],
  397. source: "interestOn: anAspect block: aBlock\x0a\x09(anAspect notEmpty and: [ anAspect last isNil ])\x0a\x09\x09ifTrue: [ ^ InterestedInTrapPathSubtree new aspect: anAspect allButLast block: aBlock ]\x0a\x09\x09ifFalse: [ ^ InterestedInTrapPath new aspect: anAspect block: aBlock ]",
  398. referencedClasses: ["InterestedInTrapPathSubtree", "InterestedInTrapPath"],
  399. //>>excludeEnd("ide");
  400. messageSends: ["ifTrue:ifFalse:", "and:", "notEmpty", "isNil", "last", "aspect:block:", "new", "allButLast"]
  401. }),
  402. $globals.Trapper);
  403. $core.addMethod(
  404. $core.method({
  405. selector: "model:",
  406. protocol: 'accessing',
  407. fn: function (anObject){
  408. var self=this;
  409. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  410. return $core.withContext(function($ctx1) {
  411. //>>excludeEnd("ctx");
  412. self["@payload"]=anObject;
  413. $recv(self._axon())._changedAll();
  414. return self;
  415. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  416. }, function($ctx1) {$ctx1.fill(self,"model:",{anObject:anObject},$globals.Trapper)});
  417. //>>excludeEnd("ctx");
  418. },
  419. //>>excludeStart("ide", pragmas.excludeIdeData);
  420. args: ["anObject"],
  421. source: "model: anObject\x0a\x09payload := anObject.\x0a self axon changedAll",
  422. referencedClasses: [],
  423. //>>excludeEnd("ide");
  424. messageSends: ["changedAll", "axon"]
  425. }),
  426. $globals.Trapper);
  427. $core.addMethod(
  428. $core.method({
  429. selector: "modify:do:",
  430. protocol: 'action',
  431. fn: function (path,aBlock){
  432. var self=this;
  433. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  434. return $core.withContext(function($ctx1) {
  435. //>>excludeEnd("ctx");
  436. self._subclassResponsibility();
  437. return self;
  438. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  439. }, function($ctx1) {$ctx1.fill(self,"modify:do:",{path:path,aBlock:aBlock},$globals.Trapper)});
  440. //>>excludeEnd("ctx");
  441. },
  442. //>>excludeStart("ide", pragmas.excludeIdeData);
  443. args: ["path", "aBlock"],
  444. source: "modify: path do: aBlock\x0a\x09self subclassResponsibility",
  445. referencedClasses: [],
  446. //>>excludeEnd("ide");
  447. messageSends: ["subclassResponsibility"]
  448. }),
  449. $globals.Trapper);
  450. $core.addMethod(
  451. $core.method({
  452. selector: "read:do:",
  453. protocol: 'action',
  454. fn: function (path,aBlock){
  455. var self=this;
  456. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  457. return $core.withContext(function($ctx1) {
  458. //>>excludeEnd("ctx");
  459. self._subclassResponsibility();
  460. return self;
  461. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  462. }, function($ctx1) {$ctx1.fill(self,"read:do:",{path:path,aBlock:aBlock},$globals.Trapper)});
  463. //>>excludeEnd("ctx");
  464. },
  465. //>>excludeStart("ide", pragmas.excludeIdeData);
  466. args: ["path", "aBlock"],
  467. source: "read: path do: aBlock\x0a\x09self subclassResponsibility",
  468. referencedClasses: [],
  469. //>>excludeEnd("ide");
  470. messageSends: ["subclassResponsibility"]
  471. }),
  472. $globals.Trapper);
  473. $core.addMethod(
  474. $core.method({
  475. selector: "watch:do:",
  476. protocol: 'action',
  477. fn: function (path,aBlock){
  478. var self=this;
  479. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  480. return $core.withContext(function($ctx1) {
  481. //>>excludeEnd("ctx");
  482. $recv(self._axon())._addInterest_(self._interestOn_block_(path,(function(){
  483. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  484. return $core.withContext(function($ctx2) {
  485. //>>excludeEnd("ctx");
  486. return self._read_do_(path,aBlock);
  487. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  488. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  489. //>>excludeEnd("ctx");
  490. })));
  491. return self;
  492. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  493. }, function($ctx1) {$ctx1.fill(self,"watch:do:",{path:path,aBlock:aBlock},$globals.Trapper)});
  494. //>>excludeEnd("ctx");
  495. },
  496. //>>excludeStart("ide", pragmas.excludeIdeData);
  497. args: ["path", "aBlock"],
  498. source: "watch: path do: aBlock\x0a\x09self axon addInterest: (self\x0a\x09\x09interestOn: path\x0a\x09\x09block: [ self read: path do: aBlock ])",
  499. referencedClasses: [],
  500. //>>excludeEnd("ide");
  501. messageSends: ["addInterest:", "axon", "interestOn:block:", "read:do:"]
  502. }),
  503. $globals.Trapper);
  504. $core.addClass('DirectTrapper', $globals.Trapper, [], 'Trapped-Backend');
  505. //>>excludeStart("ide", pragmas.excludeIdeData);
  506. $globals.DirectTrapper.comment="I am Trapper that directly manipulate\x0athe wrapped model object.";
  507. //>>excludeEnd("ide");
  508. $core.addMethod(
  509. $core.method({
  510. selector: "modify:do:",
  511. protocol: 'action',
  512. fn: function (path,aBlock){
  513. var self=this;
  514. var newValue,eavModel;
  515. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  516. return $core.withContext(function($ctx1) {
  517. //>>excludeEnd("ctx");
  518. eavModel=$recv(path)._asEavModel();
  519. newValue=$recv(aBlock)._value_($recv(eavModel)._on_(self["@payload"]));
  520. $recv((function(){
  521. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  522. return $core.withContext(function($ctx2) {
  523. //>>excludeEnd("ctx");
  524. return $recv(eavModel)._on_put_(self["@payload"],newValue);
  525. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  526. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  527. //>>excludeEnd("ctx");
  528. }))._ensure_((function(){
  529. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  530. return $core.withContext(function($ctx2) {
  531. //>>excludeEnd("ctx");
  532. return self._changed_(path);
  533. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  534. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  535. //>>excludeEnd("ctx");
  536. }));
  537. return self;
  538. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  539. }, function($ctx1) {$ctx1.fill(self,"modify:do:",{path:path,aBlock:aBlock,newValue:newValue,eavModel:eavModel},$globals.DirectTrapper)});
  540. //>>excludeEnd("ctx");
  541. },
  542. //>>excludeStart("ide", pragmas.excludeIdeData);
  543. args: ["path", "aBlock"],
  544. source: "modify: path do: aBlock\x0a | newValue eavModel |\x0a eavModel := path asEavModel.\x0a newValue := aBlock value: (eavModel on: payload).\x0a [ eavModel on: payload put: newValue ] ensure: [ self changed: path ]",
  545. referencedClasses: [],
  546. //>>excludeEnd("ide");
  547. messageSends: ["asEavModel", "value:", "on:", "ensure:", "on:put:", "changed:"]
  548. }),
  549. $globals.DirectTrapper);
  550. $core.addMethod(
  551. $core.method({
  552. selector: "read:do:",
  553. protocol: 'action',
  554. fn: function (path,aBlock){
  555. var self=this;
  556. var eavModel;
  557. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  558. return $core.withContext(function($ctx1) {
  559. //>>excludeEnd("ctx");
  560. eavModel=$recv(path)._asEavModel();
  561. $recv(aBlock)._value_($recv(eavModel)._on_(self["@payload"]));
  562. return self;
  563. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  564. }, function($ctx1) {$ctx1.fill(self,"read:do:",{path:path,aBlock:aBlock,eavModel:eavModel},$globals.DirectTrapper)});
  565. //>>excludeEnd("ctx");
  566. },
  567. //>>excludeStart("ide", pragmas.excludeIdeData);
  568. args: ["path", "aBlock"],
  569. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: payload)",
  570. referencedClasses: [],
  571. //>>excludeEnd("ide");
  572. messageSends: ["asEavModel", "value:", "on:"]
  573. }),
  574. $globals.DirectTrapper);
  575. $core.addClass('IsolatingTrapper', $globals.Trapper, [], 'Trapped-Backend');
  576. //>>excludeStart("ide", pragmas.excludeIdeData);
  577. $globals.IsolatingTrapper.comment="I am Trapper that guards access\x0ato the wrapped model object via Isolator.\x0a\x0aIOW, read:do: gets always its own deep copy,\x0amodify:do: is not reentrant\x0aand upon writing the written part is deep-copied as well\x0a(so modifier does not hold the source of truth\x0aand can change it later).\x0a\x0aThis also means, a wrapped object and all its parts\x0amust understand `#deepCopy`.";
  578. //>>excludeEnd("ide");
  579. $core.addMethod(
  580. $core.method({
  581. selector: "model:",
  582. protocol: 'accessing',
  583. fn: function (anObject){
  584. var self=this;
  585. function $Isolator(){return $globals.Isolator||(typeof Isolator=="undefined"?nil:Isolator)}
  586. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  587. return $core.withContext(function($ctx1) {
  588. //>>excludeEnd("ctx");
  589. (
  590. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  591. $ctx1.supercall = true,
  592. //>>excludeEnd("ctx");
  593. $globals.IsolatingTrapper.superclass.fn.prototype._model_.apply($recv(self), [$recv($Isolator())._on_(anObject)]));
  594. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  595. $ctx1.supercall = false;
  596. //>>excludeEnd("ctx");;
  597. return self;
  598. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  599. }, function($ctx1) {$ctx1.fill(self,"model:",{anObject:anObject},$globals.IsolatingTrapper)});
  600. //>>excludeEnd("ctx");
  601. },
  602. //>>excludeStart("ide", pragmas.excludeIdeData);
  603. args: ["anObject"],
  604. source: "model: anObject\x0a\x09super model: (Isolator on: anObject)",
  605. referencedClasses: ["Isolator"],
  606. //>>excludeEnd("ide");
  607. messageSends: ["model:", "on:"]
  608. }),
  609. $globals.IsolatingTrapper);
  610. $core.addMethod(
  611. $core.method({
  612. selector: "modify:do:",
  613. protocol: 'action',
  614. fn: function (path,aBlock){
  615. var self=this;
  616. var eavModel;
  617. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  618. return $core.withContext(function($ctx1) {
  619. //>>excludeEnd("ctx");
  620. eavModel=$recv($recv([["root"]]).__comma(path))._asEavModel();
  621. $recv((function(){
  622. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  623. return $core.withContext(function($ctx2) {
  624. //>>excludeEnd("ctx");
  625. return $recv(self["@payload"])._model_modify_(eavModel,aBlock);
  626. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  627. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  628. //>>excludeEnd("ctx");
  629. }))._ensure_((function(){
  630. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  631. return $core.withContext(function($ctx2) {
  632. //>>excludeEnd("ctx");
  633. return self._changed_(path);
  634. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  635. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  636. //>>excludeEnd("ctx");
  637. }));
  638. return self;
  639. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  640. }, function($ctx1) {$ctx1.fill(self,"modify:do:",{path:path,aBlock:aBlock,eavModel:eavModel},$globals.IsolatingTrapper)});
  641. //>>excludeEnd("ctx");
  642. },
  643. //>>excludeStart("ide", pragmas.excludeIdeData);
  644. args: ["path", "aBlock"],
  645. source: "modify: path do: aBlock\x0a | eavModel |\x0a eavModel := ({{#root}},path) asEavModel.\x0a [ payload model: eavModel modify: aBlock ] ensure: [ self changed: path ]",
  646. referencedClasses: [],
  647. //>>excludeEnd("ide");
  648. messageSends: ["asEavModel", ",", "ensure:", "model:modify:", "changed:"]
  649. }),
  650. $globals.IsolatingTrapper);
  651. $core.addMethod(
  652. $core.method({
  653. selector: "read:do:",
  654. protocol: 'action',
  655. fn: function (path,aBlock){
  656. var self=this;
  657. var eavModel;
  658. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  659. return $core.withContext(function($ctx1) {
  660. //>>excludeEnd("ctx");
  661. eavModel=$recv($recv([["root"]]).__comma(path))._asEavModel();
  662. $recv(self["@payload"])._model_read_(eavModel,aBlock);
  663. return self;
  664. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  665. }, function($ctx1) {$ctx1.fill(self,"read:do:",{path:path,aBlock:aBlock,eavModel:eavModel},$globals.IsolatingTrapper)});
  666. //>>excludeEnd("ctx");
  667. },
  668. //>>excludeStart("ide", pragmas.excludeIdeData);
  669. args: ["path", "aBlock"],
  670. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := ({{#root}},path) asEavModel.\x0a payload model: eavModel read: aBlock",
  671. referencedClasses: [],
  672. //>>excludeEnd("ide");
  673. messageSends: ["asEavModel", ",", "model:read:"]
  674. }),
  675. $globals.IsolatingTrapper);
  676. $core.addMethod(
  677. $core.method({
  678. selector: "asEavModel",
  679. protocol: '*Trapped-Backend',
  680. fn: function (){
  681. var self=this;
  682. var model;
  683. function $EavModel(){return $globals.EavModel||(typeof EavModel=="undefined"?nil:EavModel)}
  684. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  685. return $core.withContext(function($ctx1) {
  686. //>>excludeEnd("ctx");
  687. var $1,$2;
  688. model=$recv($EavModel())._new();
  689. $recv(model)._getBlock_((function(anObject){
  690. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  691. return $core.withContext(function($ctx2) {
  692. //>>excludeEnd("ctx");
  693. return $recv(anObject)._atLyst_ifAbsent_(self,(function(){
  694. return nil;
  695. }));
  696. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  697. }, function($ctx2) {$ctx2.fillBlock({anObject:anObject},$ctx1,1)});
  698. //>>excludeEnd("ctx");
  699. }));
  700. $1=self._isEmpty();
  701. if(!$core.assert($1)){
  702. $recv(model)._putBlock_((function(anObject,value){
  703. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  704. return $core.withContext(function($ctx2) {
  705. //>>excludeEnd("ctx");
  706. return $recv(anObject)._atLyst_ifAbsent_put_(self,(function(){
  707. return nil;
  708. }),value);
  709. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  710. }, function($ctx2) {$ctx2.fillBlock({anObject:anObject,value:value},$ctx1,4)});
  711. //>>excludeEnd("ctx");
  712. }));
  713. };
  714. $2=model;
  715. return $2;
  716. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  717. }, function($ctx1) {$ctx1.fill(self,"asEavModel",{model:model},$globals.SequenceableCollection)});
  718. //>>excludeEnd("ctx");
  719. },
  720. //>>excludeStart("ide", pragmas.excludeIdeData);
  721. args: [],
  722. source: "asEavModel\x0a | model |\x0a model := EavModel new.\x0a model getBlock: [ :anObject | anObject atLyst: self ifAbsent: [ nil ] ].\x0a self isEmpty ifFalse: [\x0a model putBlock: [ :anObject :value | anObject atLyst: self ifAbsent: [ nil ] put: value ]].\x0a ^model",
  723. referencedClasses: ["EavModel"],
  724. //>>excludeEnd("ide");
  725. messageSends: ["new", "getBlock:", "atLyst:ifAbsent:", "ifFalse:", "isEmpty", "putBlock:", "atLyst:ifAbsent:put:"]
  726. }),
  727. $globals.SequenceableCollection);
  728. });