Trapped-Backend.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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('TrappedPosition', $globals.Object, ['path', 'model'], 'Trapped-Backend');
  352. $core.addMethod(
  353. $core.method({
  354. selector: "model",
  355. protocol: 'accessing',
  356. fn: function (){
  357. var self=this;
  358. var $1;
  359. $1=self["@model"];
  360. return $1;
  361. },
  362. //>>excludeStart("ide", pragmas.excludeIdeData);
  363. args: [],
  364. source: "model\x0a\x09^model",
  365. referencedClasses: [],
  366. //>>excludeEnd("ide");
  367. messageSends: []
  368. }),
  369. $globals.TrappedPosition);
  370. $core.addMethod(
  371. $core.method({
  372. selector: "modify:",
  373. protocol: 'action',
  374. fn: function (aBlock){
  375. var self=this;
  376. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  377. return $core.withContext(function($ctx1) {
  378. //>>excludeEnd("ctx");
  379. $recv(self._model())._modify_do_(self._path(),aBlock);
  380. return self;
  381. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  382. }, function($ctx1) {$ctx1.fill(self,"modify:",{aBlock:aBlock},$globals.TrappedPosition)});
  383. //>>excludeEnd("ctx");
  384. },
  385. //>>excludeStart("ide", pragmas.excludeIdeData);
  386. args: ["aBlock"],
  387. source: "modify: aBlock\x0a\x09self model modify: self path do: aBlock",
  388. referencedClasses: [],
  389. //>>excludeEnd("ide");
  390. messageSends: ["modify:do:", "model", "path"]
  391. }),
  392. $globals.TrappedPosition);
  393. $core.addMethod(
  394. $core.method({
  395. selector: "path",
  396. protocol: 'accessing',
  397. fn: function (){
  398. var self=this;
  399. var $1;
  400. $1=self["@path"];
  401. return $1;
  402. },
  403. //>>excludeStart("ide", pragmas.excludeIdeData);
  404. args: [],
  405. source: "path\x0a\x09^path",
  406. referencedClasses: [],
  407. //>>excludeEnd("ide");
  408. messageSends: []
  409. }),
  410. $globals.TrappedPosition);
  411. $core.addMethod(
  412. $core.method({
  413. selector: "path:model:",
  414. protocol: 'accessing',
  415. fn: function (anArray,aTrappedMW){
  416. var self=this;
  417. self["@path"]=anArray;
  418. self["@model"]=aTrappedMW;
  419. return self;
  420. },
  421. //>>excludeStart("ide", pragmas.excludeIdeData);
  422. args: ["anArray", "aTrappedMW"],
  423. source: "path: anArray model: aTrappedMW\x0a\x09path := anArray.\x0a model := aTrappedMW",
  424. referencedClasses: [],
  425. //>>excludeEnd("ide");
  426. messageSends: []
  427. }),
  428. $globals.TrappedPosition);
  429. $core.addMethod(
  430. $core.method({
  431. selector: "read:",
  432. protocol: 'action',
  433. fn: function (aBlock){
  434. var self=this;
  435. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  436. return $core.withContext(function($ctx1) {
  437. //>>excludeEnd("ctx");
  438. $recv(self._model())._read_do_(self._path(),aBlock);
  439. return self;
  440. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  441. }, function($ctx1) {$ctx1.fill(self,"read:",{aBlock:aBlock},$globals.TrappedPosition)});
  442. //>>excludeEnd("ctx");
  443. },
  444. //>>excludeStart("ide", pragmas.excludeIdeData);
  445. args: ["aBlock"],
  446. source: "read: aBlock\x0a\x09self model read: self path do: aBlock",
  447. referencedClasses: [],
  448. //>>excludeEnd("ide");
  449. messageSends: ["read:do:", "model", "path"]
  450. }),
  451. $globals.TrappedPosition);
  452. $core.addMethod(
  453. $core.method({
  454. selector: "watch:",
  455. protocol: 'action',
  456. fn: function (aBlock){
  457. var self=this;
  458. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  459. return $core.withContext(function($ctx1) {
  460. //>>excludeEnd("ctx");
  461. $recv(self._model())._watch_do_(self._path(),aBlock);
  462. return self;
  463. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  464. }, function($ctx1) {$ctx1.fill(self,"watch:",{aBlock:aBlock},$globals.TrappedPosition)});
  465. //>>excludeEnd("ctx");
  466. },
  467. //>>excludeStart("ide", pragmas.excludeIdeData);
  468. args: ["aBlock"],
  469. source: "watch: aBlock\x0a\x09self model watch: self path do: aBlock",
  470. referencedClasses: [],
  471. //>>excludeEnd("ide");
  472. messageSends: ["watch:do:", "model", "path"]
  473. }),
  474. $globals.TrappedPosition);
  475. $core.addClass('Trapper', $globals.AxonizedObject, ['payload'], 'Trapped-Backend');
  476. //>>excludeStart("ide", pragmas.excludeIdeData);
  477. $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:`)";
  478. //>>excludeEnd("ide");
  479. $core.addMethod(
  480. $core.method({
  481. selector: "interestOn:block:",
  482. protocol: 'action',
  483. fn: function (anAspect,aBlock){
  484. var self=this;
  485. function $InterestedInTrapPathSubtree(){return $globals.InterestedInTrapPathSubtree||(typeof InterestedInTrapPathSubtree=="undefined"?nil:InterestedInTrapPathSubtree)}
  486. function $InterestedInTrapPath(){return $globals.InterestedInTrapPath||(typeof InterestedInTrapPath=="undefined"?nil:InterestedInTrapPath)}
  487. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  488. return $core.withContext(function($ctx1) {
  489. //>>excludeEnd("ctx");
  490. var $1,$3,$2,$4;
  491. $1=$recv($recv(anAspect)._notEmpty())._and_((function(){
  492. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  493. return $core.withContext(function($ctx2) {
  494. //>>excludeEnd("ctx");
  495. return $recv($recv(anAspect)._last())._isNil();
  496. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  497. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  498. //>>excludeEnd("ctx");
  499. }));
  500. if($core.assert($1)){
  501. $3=$recv($InterestedInTrapPathSubtree())._new();
  502. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  503. $ctx1.sendIdx["new"]=1;
  504. //>>excludeEnd("ctx");
  505. $2=$recv($3)._aspect_block_($recv(anAspect)._allButLast(),aBlock);
  506. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  507. $ctx1.sendIdx["aspect:block:"]=1;
  508. //>>excludeEnd("ctx");
  509. return $2;
  510. } else {
  511. $4=$recv($recv($InterestedInTrapPath())._new())._aspect_block_(anAspect,aBlock);
  512. return $4;
  513. };
  514. return self;
  515. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  516. }, function($ctx1) {$ctx1.fill(self,"interestOn:block:",{anAspect:anAspect,aBlock:aBlock},$globals.Trapper)});
  517. //>>excludeEnd("ctx");
  518. },
  519. //>>excludeStart("ide", pragmas.excludeIdeData);
  520. args: ["anAspect", "aBlock"],
  521. 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 ]",
  522. referencedClasses: ["InterestedInTrapPathSubtree", "InterestedInTrapPath"],
  523. //>>excludeEnd("ide");
  524. messageSends: ["ifTrue:ifFalse:", "and:", "notEmpty", "isNil", "last", "aspect:block:", "new", "allButLast"]
  525. }),
  526. $globals.Trapper);
  527. $core.addMethod(
  528. $core.method({
  529. selector: "model:",
  530. protocol: 'accessing',
  531. fn: function (anObject){
  532. var self=this;
  533. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  534. return $core.withContext(function($ctx1) {
  535. //>>excludeEnd("ctx");
  536. self["@payload"]=anObject;
  537. $recv(self._axon())._changedAll();
  538. return self;
  539. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  540. }, function($ctx1) {$ctx1.fill(self,"model:",{anObject:anObject},$globals.Trapper)});
  541. //>>excludeEnd("ctx");
  542. },
  543. //>>excludeStart("ide", pragmas.excludeIdeData);
  544. args: ["anObject"],
  545. source: "model: anObject\x0a\x09payload := anObject.\x0a self axon changedAll",
  546. referencedClasses: [],
  547. //>>excludeEnd("ide");
  548. messageSends: ["changedAll", "axon"]
  549. }),
  550. $globals.Trapper);
  551. $core.addMethod(
  552. $core.method({
  553. selector: "modify:do:",
  554. protocol: 'action',
  555. fn: function (path,aBlock){
  556. var self=this;
  557. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  558. return $core.withContext(function($ctx1) {
  559. //>>excludeEnd("ctx");
  560. self._subclassResponsibility();
  561. return self;
  562. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  563. }, function($ctx1) {$ctx1.fill(self,"modify:do:",{path:path,aBlock:aBlock},$globals.Trapper)});
  564. //>>excludeEnd("ctx");
  565. },
  566. //>>excludeStart("ide", pragmas.excludeIdeData);
  567. args: ["path", "aBlock"],
  568. source: "modify: path do: aBlock\x0a\x09self subclassResponsibility",
  569. referencedClasses: [],
  570. //>>excludeEnd("ide");
  571. messageSends: ["subclassResponsibility"]
  572. }),
  573. $globals.Trapper);
  574. $core.addMethod(
  575. $core.method({
  576. selector: "read:do:",
  577. protocol: 'action',
  578. fn: function (path,aBlock){
  579. var self=this;
  580. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  581. return $core.withContext(function($ctx1) {
  582. //>>excludeEnd("ctx");
  583. self._subclassResponsibility();
  584. return self;
  585. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  586. }, function($ctx1) {$ctx1.fill(self,"read:do:",{path:path,aBlock:aBlock},$globals.Trapper)});
  587. //>>excludeEnd("ctx");
  588. },
  589. //>>excludeStart("ide", pragmas.excludeIdeData);
  590. args: ["path", "aBlock"],
  591. source: "read: path do: aBlock\x0a\x09self subclassResponsibility",
  592. referencedClasses: [],
  593. //>>excludeEnd("ide");
  594. messageSends: ["subclassResponsibility"]
  595. }),
  596. $globals.Trapper);
  597. $core.addMethod(
  598. $core.method({
  599. selector: "watch:do:",
  600. protocol: 'action',
  601. fn: function (path,aBlock){
  602. var self=this;
  603. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  604. return $core.withContext(function($ctx1) {
  605. //>>excludeEnd("ctx");
  606. $recv(self._axon())._addInterest_(self._interestOn_block_(path,(function(){
  607. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  608. return $core.withContext(function($ctx2) {
  609. //>>excludeEnd("ctx");
  610. return self._read_do_(path,aBlock);
  611. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  612. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  613. //>>excludeEnd("ctx");
  614. })));
  615. return self;
  616. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  617. }, function($ctx1) {$ctx1.fill(self,"watch:do:",{path:path,aBlock:aBlock},$globals.Trapper)});
  618. //>>excludeEnd("ctx");
  619. },
  620. //>>excludeStart("ide", pragmas.excludeIdeData);
  621. args: ["path", "aBlock"],
  622. source: "watch: path do: aBlock\x0a\x09self axon addInterest: (self\x0a\x09\x09interestOn: path\x0a\x09\x09block: [ self read: path do: aBlock ])",
  623. referencedClasses: [],
  624. //>>excludeEnd("ide");
  625. messageSends: ["addInterest:", "axon", "interestOn:block:", "read:do:"]
  626. }),
  627. $globals.Trapper);
  628. $core.addClass('DirectTrapper', $globals.Trapper, [], 'Trapped-Backend');
  629. //>>excludeStart("ide", pragmas.excludeIdeData);
  630. $globals.DirectTrapper.comment="I am Trapper that directly manipulate\x0athe wrapped model object.";
  631. //>>excludeEnd("ide");
  632. $core.addMethod(
  633. $core.method({
  634. selector: "modify:do:",
  635. protocol: 'action',
  636. fn: function (path,aBlock){
  637. var self=this;
  638. var newValue,eavModel;
  639. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  640. return $core.withContext(function($ctx1) {
  641. //>>excludeEnd("ctx");
  642. eavModel=$recv(path)._asEavModel();
  643. newValue=$recv(aBlock)._value_($recv(eavModel)._on_(self["@payload"]));
  644. $recv((function(){
  645. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  646. return $core.withContext(function($ctx2) {
  647. //>>excludeEnd("ctx");
  648. return $recv(eavModel)._on_put_(self["@payload"],newValue);
  649. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  650. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  651. //>>excludeEnd("ctx");
  652. }))._ensure_((function(){
  653. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  654. return $core.withContext(function($ctx2) {
  655. //>>excludeEnd("ctx");
  656. return self._changed_(path);
  657. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  658. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  659. //>>excludeEnd("ctx");
  660. }));
  661. return self;
  662. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  663. }, function($ctx1) {$ctx1.fill(self,"modify:do:",{path:path,aBlock:aBlock,newValue:newValue,eavModel:eavModel},$globals.DirectTrapper)});
  664. //>>excludeEnd("ctx");
  665. },
  666. //>>excludeStart("ide", pragmas.excludeIdeData);
  667. args: ["path", "aBlock"],
  668. 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 ]",
  669. referencedClasses: [],
  670. //>>excludeEnd("ide");
  671. messageSends: ["asEavModel", "value:", "on:", "ensure:", "on:put:", "changed:"]
  672. }),
  673. $globals.DirectTrapper);
  674. $core.addMethod(
  675. $core.method({
  676. selector: "read:do:",
  677. protocol: 'action',
  678. fn: function (path,aBlock){
  679. var self=this;
  680. var eavModel;
  681. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  682. return $core.withContext(function($ctx1) {
  683. //>>excludeEnd("ctx");
  684. eavModel=$recv(path)._asEavModel();
  685. $recv(aBlock)._value_($recv(eavModel)._on_(self["@payload"]));
  686. return self;
  687. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  688. }, function($ctx1) {$ctx1.fill(self,"read:do:",{path:path,aBlock:aBlock,eavModel:eavModel},$globals.DirectTrapper)});
  689. //>>excludeEnd("ctx");
  690. },
  691. //>>excludeStart("ide", pragmas.excludeIdeData);
  692. args: ["path", "aBlock"],
  693. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: payload)",
  694. referencedClasses: [],
  695. //>>excludeEnd("ide");
  696. messageSends: ["asEavModel", "value:", "on:"]
  697. }),
  698. $globals.DirectTrapper);
  699. $core.addClass('IsolatingTrapper', $globals.Trapper, [], 'Trapped-Backend');
  700. //>>excludeStart("ide", pragmas.excludeIdeData);
  701. $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`.";
  702. //>>excludeEnd("ide");
  703. $core.addMethod(
  704. $core.method({
  705. selector: "model:",
  706. protocol: 'accessing',
  707. fn: function (anObject){
  708. var self=this;
  709. function $Isolator(){return $globals.Isolator||(typeof Isolator=="undefined"?nil:Isolator)}
  710. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  711. return $core.withContext(function($ctx1) {
  712. //>>excludeEnd("ctx");
  713. (
  714. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  715. $ctx1.supercall = true,
  716. //>>excludeEnd("ctx");
  717. $globals.IsolatingTrapper.superclass.fn.prototype._model_.apply($recv(self), [$recv($Isolator())._on_(anObject)]));
  718. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  719. $ctx1.supercall = false;
  720. //>>excludeEnd("ctx");;
  721. return self;
  722. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  723. }, function($ctx1) {$ctx1.fill(self,"model:",{anObject:anObject},$globals.IsolatingTrapper)});
  724. //>>excludeEnd("ctx");
  725. },
  726. //>>excludeStart("ide", pragmas.excludeIdeData);
  727. args: ["anObject"],
  728. source: "model: anObject\x0a\x09super model: (Isolator on: anObject)",
  729. referencedClasses: ["Isolator"],
  730. //>>excludeEnd("ide");
  731. messageSends: ["model:", "on:"]
  732. }),
  733. $globals.IsolatingTrapper);
  734. $core.addMethod(
  735. $core.method({
  736. selector: "modify:do:",
  737. protocol: 'action',
  738. fn: function (path,aBlock){
  739. var self=this;
  740. var eavModel;
  741. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  742. return $core.withContext(function($ctx1) {
  743. //>>excludeEnd("ctx");
  744. eavModel=$recv($recv([["root"]]).__comma(path))._asEavModel();
  745. $recv((function(){
  746. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  747. return $core.withContext(function($ctx2) {
  748. //>>excludeEnd("ctx");
  749. return $recv(self["@payload"])._model_modify_(eavModel,aBlock);
  750. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  751. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  752. //>>excludeEnd("ctx");
  753. }))._ensure_((function(){
  754. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  755. return $core.withContext(function($ctx2) {
  756. //>>excludeEnd("ctx");
  757. return self._changed_(path);
  758. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  759. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  760. //>>excludeEnd("ctx");
  761. }));
  762. return self;
  763. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  764. }, function($ctx1) {$ctx1.fill(self,"modify:do:",{path:path,aBlock:aBlock,eavModel:eavModel},$globals.IsolatingTrapper)});
  765. //>>excludeEnd("ctx");
  766. },
  767. //>>excludeStart("ide", pragmas.excludeIdeData);
  768. args: ["path", "aBlock"],
  769. source: "modify: path do: aBlock\x0a | eavModel |\x0a eavModel := ({{#root}},path) asEavModel.\x0a [ payload model: eavModel modify: aBlock ] ensure: [ self changed: path ]",
  770. referencedClasses: [],
  771. //>>excludeEnd("ide");
  772. messageSends: ["asEavModel", ",", "ensure:", "model:modify:", "changed:"]
  773. }),
  774. $globals.IsolatingTrapper);
  775. $core.addMethod(
  776. $core.method({
  777. selector: "read:do:",
  778. protocol: 'action',
  779. fn: function (path,aBlock){
  780. var self=this;
  781. var eavModel;
  782. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  783. return $core.withContext(function($ctx1) {
  784. //>>excludeEnd("ctx");
  785. eavModel=$recv($recv([["root"]]).__comma(path))._asEavModel();
  786. $recv(self["@payload"])._model_read_(eavModel,aBlock);
  787. return self;
  788. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  789. }, function($ctx1) {$ctx1.fill(self,"read:do:",{path:path,aBlock:aBlock,eavModel:eavModel},$globals.IsolatingTrapper)});
  790. //>>excludeEnd("ctx");
  791. },
  792. //>>excludeStart("ide", pragmas.excludeIdeData);
  793. args: ["path", "aBlock"],
  794. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := ({{#root}},path) asEavModel.\x0a payload model: eavModel read: aBlock",
  795. referencedClasses: [],
  796. //>>excludeEnd("ide");
  797. messageSends: ["asEavModel", ",", "model:read:"]
  798. }),
  799. $globals.IsolatingTrapper);
  800. $core.addMethod(
  801. $core.method({
  802. selector: "asEavModel",
  803. protocol: '*Trapped-Backend',
  804. fn: function (){
  805. var self=this;
  806. var model;
  807. function $EavModel(){return $globals.EavModel||(typeof EavModel=="undefined"?nil:EavModel)}
  808. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  809. return $core.withContext(function($ctx1) {
  810. //>>excludeEnd("ctx");
  811. var $1,$2;
  812. model=$recv($EavModel())._new();
  813. $recv(model)._getBlock_((function(anObject){
  814. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  815. return $core.withContext(function($ctx2) {
  816. //>>excludeEnd("ctx");
  817. return $recv(anObject)._atLyst_ifAbsent_(self,(function(){
  818. return nil;
  819. }));
  820. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  821. }, function($ctx2) {$ctx2.fillBlock({anObject:anObject},$ctx1,1)});
  822. //>>excludeEnd("ctx");
  823. }));
  824. $1=self._isEmpty();
  825. if(!$core.assert($1)){
  826. $recv(model)._putBlock_((function(anObject,value){
  827. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  828. return $core.withContext(function($ctx2) {
  829. //>>excludeEnd("ctx");
  830. return $recv(anObject)._atLyst_ifAbsent_put_(self,(function(){
  831. return nil;
  832. }),value);
  833. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  834. }, function($ctx2) {$ctx2.fillBlock({anObject:anObject,value:value},$ctx1,4)});
  835. //>>excludeEnd("ctx");
  836. }));
  837. };
  838. $2=model;
  839. return $2;
  840. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  841. }, function($ctx1) {$ctx1.fill(self,"asEavModel",{model:model},$globals.SequenceableCollection)});
  842. //>>excludeEnd("ctx");
  843. },
  844. //>>excludeStart("ide", pragmas.excludeIdeData);
  845. args: [],
  846. 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",
  847. referencedClasses: ["EavModel"],
  848. //>>excludeEnd("ide");
  849. messageSends: ["new", "getBlock:", "atLyst:ifAbsent:", "ifFalse:", "isEmpty", "putBlock:", "atLyst:ifAbsent:put:"]
  850. }),
  851. $globals.SequenceableCollection);
  852. });