Trapped-Backend.js 27 KB

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