Trapped-Frontend.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. smalltalk.addPackage('Trapped-Frontend', {});
  2. smalltalk.addClass('TrappedBinder', smalltalk.Object, ['brush'], 'Trapped-Frontend');
  3. smalltalk.addMethod(
  4. "_brush_",
  5. smalltalk.method({
  6. selector: "brush:",
  7. category: 'accessing',
  8. fn: function (aTagBrush){
  9. var self=this;
  10. self["@brush"]=aTagBrush;
  11. return self},
  12. args: ["aTagBrush"],
  13. source: "brush: aTagBrush\x0a\x09brush := aTagBrush",
  14. messageSends: [],
  15. referencedClasses: []
  16. }),
  17. smalltalk.TrappedBinder);
  18. smalltalk.addMethod(
  19. "_installFor_",
  20. smalltalk.method({
  21. selector: "installFor:",
  22. category: 'action',
  23. fn: function (path){
  24. var self=this;
  25. smalltalk.send(self["@brush"],"_trap_read_",[path,smalltalk.send(self,"_showBlock",[])]);
  26. return self},
  27. args: ["path"],
  28. source: "installFor: path\x0a\x09brush trap: path read: self showBlock",
  29. messageSends: ["trap:read:", "showBlock"],
  30. referencedClasses: []
  31. }),
  32. smalltalk.TrappedBinder);
  33. smalltalk.addMethod(
  34. "_prim_",
  35. smalltalk.method({
  36. selector: "prim:",
  37. category: 'converting',
  38. fn: function (anObject){
  39. var self=this;
  40. return anObject.valueOf();
  41. ;
  42. return self},
  43. args: ["anObject"],
  44. source: "prim: anObject\x0a\x09<return anObject.valueOf()>",
  45. messageSends: [],
  46. referencedClasses: []
  47. }),
  48. smalltalk.TrappedBinder);
  49. smalltalk.addMethod(
  50. "_showBlock",
  51. smalltalk.method({
  52. selector: "showBlock",
  53. category: 'action',
  54. fn: function (){
  55. var self=this;
  56. var $3,$2,$1;
  57. $1=(function(model){
  58. smalltalk.send(self["@brush"],"_empty",[]);
  59. if(($receiver = model) == nil || $receiver == undefined){
  60. $3=(function(){
  61. });
  62. } else {
  63. $3=model;
  64. };
  65. $2=smalltalk.send(self["@brush"],"_with_",[$3]);
  66. return $2;
  67. });
  68. return $1;
  69. },
  70. args: [],
  71. source: "showBlock\x0a\x09^[ :model | brush empty; with: (model ifNil: [[]]) ]",
  72. messageSends: ["empty", "with:", "ifNil:"],
  73. referencedClasses: []
  74. }),
  75. smalltalk.TrappedBinder);
  76. smalltalk.addClass('TrappedAttrBinder', smalltalk.TrappedBinder, ['attr'], 'Trapped-Frontend');
  77. smalltalk.addMethod(
  78. "_attr_",
  79. smalltalk.method({
  80. selector: "attr:",
  81. category: 'accessing',
  82. fn: function (aString){
  83. var self=this;
  84. self["@attr"]=aString;
  85. return self},
  86. args: ["aString"],
  87. source: "attr: aString\x0a\x09attr := aString",
  88. messageSends: [],
  89. referencedClasses: []
  90. }),
  91. smalltalk.TrappedAttrBinder);
  92. smalltalk.addMethod(
  93. "_installFor_",
  94. smalltalk.method({
  95. selector: "installFor:",
  96. category: 'action',
  97. fn: function (path){
  98. var self=this;
  99. smalltalk.send(self,"_installFor_",[path],smalltalk.TrappedBinder);
  100. smalltalk.send(path,"_trapDescend_",[(function(snap){
  101. return smalltalk.send(self["@brush"],"_onChange_",[(function(){
  102. return smalltalk.send(snap,"_modify_",[(function(){
  103. return smalltalk.send(smalltalk.send(smalltalk.send(self["@brush"],"_asJQuery",[]),"_attr_",["checked"]),"_notNil",[]);
  104. })]);
  105. })]);
  106. })]);
  107. return self},
  108. args: ["path"],
  109. source: "installFor: path\x0a\x09super installFor: path.\x0a path trapDescend: [ :snap |\x0a\x09 brush onChange: [ snap modify: [\x0a (brush asJQuery attr: 'checked') notNil\x0a ]]\x0a ]",
  110. messageSends: ["installFor:", "trapDescend:", "onChange:", "modify:", "notNil", "attr:", "asJQuery"],
  111. referencedClasses: []
  112. }),
  113. smalltalk.TrappedAttrBinder);
  114. smalltalk.addMethod(
  115. "_showBlock",
  116. smalltalk.method({
  117. selector: "showBlock",
  118. category: 'action',
  119. fn: function (){
  120. var self=this;
  121. var $1;
  122. $1=(function(model){
  123. return smalltalk.send(smalltalk.send(self["@brush"],"_asJQuery",[]),"_attr_put_",[self["@attr"],smalltalk.send(self,"_prim_",[model])]);
  124. });
  125. return $1;
  126. },
  127. args: [],
  128. source: "showBlock\x0a\x09^[ :model | brush asJQuery attr: attr put: (self prim: model) ]",
  129. messageSends: ["attr:put:", "prim:", "asJQuery"],
  130. referencedClasses: []
  131. }),
  132. smalltalk.TrappedAttrBinder);
  133. smalltalk.addClass('TrappedDispatcher', smalltalk.KeyedPubSubBase, [], 'Trapped-Frontend');
  134. smalltalk.TrappedDispatcher.comment="I am base class for change event dispatchers.\x0aI manage changed path - action block subscriptions.\x0aThese subscription are instances of TrappedSubscription\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09add:\x0a do:\x0a clean\x0a (optionally) run\x0a"
  135. smalltalk.addMethod(
  136. "_subscriptionKey_block_",
  137. smalltalk.method({
  138. selector: "subscriptionKey:block:",
  139. category: 'action',
  140. fn: function (key,aBlock){
  141. var self=this;
  142. var $2,$3,$1;
  143. $2=smalltalk.send((smalltalk.TrappedSubscription || TrappedSubscription),"_new",[]);
  144. smalltalk.send($2,"_key_block_",[key,aBlock]);
  145. $3=smalltalk.send($2,"_yourself",[]);
  146. $1=$3;
  147. return $1;
  148. },
  149. args: ["key", "aBlock"],
  150. source: "subscriptionKey: key block: aBlock\x0a\x09^TrappedSubscription new key: key block: aBlock; yourself\x0a",
  151. messageSends: ["key:block:", "new", "yourself"],
  152. referencedClasses: ["TrappedSubscription"]
  153. }),
  154. smalltalk.TrappedDispatcher);
  155. smalltalk.addClass('TrappedDumbView', smalltalk.Widget, [], 'Trapped-Frontend');
  156. smalltalk.TrappedDumbView.comment="I just read and show an actual path."
  157. smalltalk.addMethod(
  158. "_renderOn_",
  159. smalltalk.method({
  160. selector: "renderOn:",
  161. category: 'rendering',
  162. fn: function (html){
  163. var self=this;
  164. smalltalk.send(smalltalk.send(html,"_root",[]),"_trap_",[[]]);
  165. return self},
  166. args: ["html"],
  167. source: "renderOn: html\x0a\x09html root trap: #()",
  168. messageSends: ["trap:", "root"],
  169. referencedClasses: []
  170. }),
  171. smalltalk.TrappedDumbView);
  172. smalltalk.addClass('TrappedModelWrapper', smalltalk.Object, ['dispatcher', 'payload'], 'Trapped-Frontend');
  173. smalltalk.TrappedModelWrapper.comment="I am base class for model wrappers.\x0aI wrap a model which can be any object.\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09read:do:\x0a modify:do:\x0a\x09(optionally) name\x0a\x0aand must issue these call when initializing:\x0a\x09model:\x0a\x09dispatcher: (with a subclass of TrappedDispatcher)\x0a"
  174. smalltalk.addMethod(
  175. "_dispatcher",
  176. smalltalk.method({
  177. selector: "dispatcher",
  178. category: 'accessing',
  179. fn: function (){
  180. var self=this;
  181. return self["@dispatcher"];
  182. },
  183. args: [],
  184. source: "dispatcher\x0a\x09^dispatcher",
  185. messageSends: [],
  186. referencedClasses: []
  187. }),
  188. smalltalk.TrappedModelWrapper);
  189. smalltalk.addMethod(
  190. "_dispatcher_",
  191. smalltalk.method({
  192. selector: "dispatcher:",
  193. category: 'accessing',
  194. fn: function (aDispatcher){
  195. var self=this;
  196. self["@dispatcher"]=aDispatcher;
  197. return self},
  198. args: ["aDispatcher"],
  199. source: "dispatcher: aDispatcher\x0a\x09dispatcher := aDispatcher",
  200. messageSends: [],
  201. referencedClasses: []
  202. }),
  203. smalltalk.TrappedModelWrapper);
  204. smalltalk.addMethod(
  205. "_model_",
  206. smalltalk.method({
  207. selector: "model:",
  208. category: 'accessing',
  209. fn: function (anObject){
  210. var self=this;
  211. self["@payload"]=anObject;
  212. smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[[]]);
  213. return self},
  214. args: ["anObject"],
  215. source: "model: anObject\x0a\x09payload := anObject.\x0a self dispatcher changed: #()",
  216. messageSends: ["changed:", "dispatcher"],
  217. referencedClasses: []
  218. }),
  219. smalltalk.TrappedModelWrapper);
  220. smalltalk.addMethod(
  221. "_name",
  222. smalltalk.method({
  223. selector: "name",
  224. category: 'accessing',
  225. fn: function (){
  226. var self=this;
  227. var $1;
  228. $1=smalltalk.send(smalltalk.send(self,"_class",[]),"_name",[]);
  229. return $1;
  230. },
  231. args: [],
  232. source: "name\x0a\x09^ self class name",
  233. messageSends: ["name", "class"],
  234. referencedClasses: []
  235. }),
  236. smalltalk.TrappedModelWrapper);
  237. smalltalk.addMethod(
  238. "_start",
  239. smalltalk.method({
  240. selector: "start",
  241. category: 'action',
  242. fn: function (){
  243. var self=this;
  244. smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_register_name_",[self,smalltalk.send(self,"_name",[])]);
  245. return self},
  246. args: [],
  247. source: "start\x0a\x09Trapped current register: self name: self name",
  248. messageSends: ["register:name:", "name", "current"],
  249. referencedClasses: ["Trapped"]
  250. }),
  251. smalltalk.TrappedModelWrapper);
  252. smalltalk.addMethod(
  253. "_watch_do_",
  254. smalltalk.method({
  255. selector: "watch:do:",
  256. category: 'action',
  257. fn: function (path,aBlock){
  258. var self=this;
  259. smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_on_hook_",[path,(function(){
  260. return smalltalk.send(self,"_read_do_",[path,aBlock]);
  261. })]);
  262. return self},
  263. args: ["path", "aBlock"],
  264. source: "watch: path do: aBlock\x0a\x09self dispatcher on: path hook: [ self read: path do: aBlock ]\x0a",
  265. messageSends: ["on:hook:", "read:do:", "dispatcher"],
  266. referencedClasses: []
  267. }),
  268. smalltalk.TrappedModelWrapper);
  269. smalltalk.addMethod(
  270. "_start",
  271. smalltalk.method({
  272. selector: "start",
  273. category: 'action',
  274. fn: function (){
  275. var self=this;
  276. var $2,$3,$1;
  277. $2=smalltalk.send(self,"_new",[]);
  278. smalltalk.send($2,"_start",[]);
  279. $3=smalltalk.send($2,"_yourself",[]);
  280. $1=$3;
  281. return $1;
  282. },
  283. args: [],
  284. source: "start\x0a\x09^self new start; yourself",
  285. messageSends: ["start", "new", "yourself"],
  286. referencedClasses: []
  287. }),
  288. smalltalk.TrappedModelWrapper.klass);
  289. smalltalk.addClass('TrappedMWDirect', smalltalk.TrappedModelWrapper, [], 'Trapped-Frontend');
  290. smalltalk.TrappedMWDirect.comment="I am TrappedModelWrapper that directly manipulate\x0athe object passed to model:"
  291. smalltalk.addMethod(
  292. "_modify_do_",
  293. smalltalk.method({
  294. selector: "modify:do:",
  295. category: 'action',
  296. fn: function (path,aBlock){
  297. var self=this;
  298. var newValue;
  299. var eavModel;
  300. eavModel=smalltalk.send(path,"_asEavModel",[]);
  301. newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[self["@payload"]])]);
  302. smalltalk.send((function(){
  303. return smalltalk.send(eavModel,"_on_put_",[self["@payload"],newValue]);
  304. }),"_ensure_",[(function(){
  305. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  306. })]);
  307. return self},
  308. args: ["path", "aBlock"],
  309. 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 dispatcher changed: path ]\x0a",
  310. messageSends: ["asEavModel", "value:", "on:", "ensure:", "changed:", "dispatcher", "on:put:"],
  311. referencedClasses: []
  312. }),
  313. smalltalk.TrappedMWDirect);
  314. smalltalk.addMethod(
  315. "_read_do_",
  316. smalltalk.method({
  317. selector: "read:do:",
  318. category: 'action',
  319. fn: function (path,aBlock){
  320. var self=this;
  321. var eavModel;
  322. eavModel=smalltalk.send(path,"_asEavModel",[]);
  323. smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[self["@payload"]])]);
  324. return self},
  325. args: ["path", "aBlock"],
  326. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: payload)\x0a",
  327. messageSends: ["asEavModel", "value:", "on:"],
  328. referencedClasses: []
  329. }),
  330. smalltalk.TrappedMWDirect);
  331. smalltalk.addClass('TrappedMWIsolated', smalltalk.TrappedModelWrapper, [], 'Trapped-Frontend');
  332. smalltalk.TrappedMWIsolated.comment="I am TrappedModelWrapper than wrap access\x0ato an object passed to model: via Isolator."
  333. smalltalk.addMethod(
  334. "_model_",
  335. smalltalk.method({
  336. selector: "model:",
  337. category: 'accessing',
  338. fn: function (anObject){
  339. var self=this;
  340. smalltalk.send(self,"_model_",[smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[anObject])],smalltalk.TrappedModelWrapper);
  341. return self},
  342. args: ["anObject"],
  343. source: "model: anObject\x0a\x09super model: (Isolator on: anObject)",
  344. messageSends: ["model:", "on:"],
  345. referencedClasses: ["Isolator"]
  346. }),
  347. smalltalk.TrappedMWIsolated);
  348. smalltalk.addMethod(
  349. "_modify_do_",
  350. smalltalk.method({
  351. selector: "modify:do:",
  352. category: 'action',
  353. fn: function (path,aBlock){
  354. var self=this;
  355. var eavModel;
  356. eavModel=smalltalk.send(smalltalk.send([smalltalk.symbolFor("root")],"__comma",[path]),"_asEavModel",[]);
  357. smalltalk.send((function(){
  358. return smalltalk.send(self["@payload"],"_model_modify_",[eavModel,aBlock]);
  359. }),"_ensure_",[(function(){
  360. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  361. })]);
  362. return self},
  363. args: ["path", "aBlock"],
  364. source: "modify: path do: aBlock\x0a | eavModel |\x0a eavModel := ({#root},path) asEavModel.\x0a [ payload model: eavModel modify: aBlock ] ensure: [ self dispatcher changed: path ]\x0a",
  365. messageSends: ["asEavModel", ",", "ensure:", "changed:", "dispatcher", "model:modify:"],
  366. referencedClasses: []
  367. }),
  368. smalltalk.TrappedMWIsolated);
  369. smalltalk.addMethod(
  370. "_read_do_",
  371. smalltalk.method({
  372. selector: "read:do:",
  373. category: 'action',
  374. fn: function (path,aBlock){
  375. var self=this;
  376. var eavModel;
  377. eavModel=smalltalk.send(smalltalk.send([smalltalk.symbolFor("root")],"__comma",[path]),"_asEavModel",[]);
  378. smalltalk.send(self["@payload"],"_model_read_",[eavModel,aBlock]);
  379. return self},
  380. args: ["path", "aBlock"],
  381. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := ({#root},path) asEavModel.\x0a payload model: eavModel read: aBlock\x0a",
  382. messageSends: ["asEavModel", ",", "model:read:"],
  383. referencedClasses: []
  384. }),
  385. smalltalk.TrappedMWIsolated);
  386. smalltalk.addClass('TrappedSingleton', smalltalk.Object, [], 'Trapped-Frontend');
  387. smalltalk.addMethod(
  388. "_start",
  389. smalltalk.method({
  390. selector: "start",
  391. category: 'action',
  392. fn: function (){
  393. var self=this;
  394. var $1;
  395. $1=smalltalk.send(self,"_subclassResponsibility",[]);
  396. return $1;
  397. },
  398. args: [],
  399. source: "start\x0a\x09^ self subclassResponsibility",
  400. messageSends: ["subclassResponsibility"],
  401. referencedClasses: []
  402. }),
  403. smalltalk.TrappedSingleton);
  404. smalltalk.TrappedSingleton.klass.iVarNames = ['current'];
  405. smalltalk.addMethod(
  406. "_current",
  407. smalltalk.method({
  408. selector: "current",
  409. category: 'accessing',
  410. fn: function (){
  411. var self=this;
  412. var $1;
  413. if(($receiver = self["@current"]) == nil || $receiver == undefined){
  414. self["@current"]=smalltalk.send(self,"_new",[]);
  415. $1=self["@current"];
  416. } else {
  417. $1=self["@current"];
  418. };
  419. return $1;
  420. },
  421. args: [],
  422. source: "current\x0a\x09^ current ifNil: [ current := self new ]",
  423. messageSends: ["ifNil:", "new"],
  424. referencedClasses: []
  425. }),
  426. smalltalk.TrappedSingleton.klass);
  427. smalltalk.addMethod(
  428. "_start",
  429. smalltalk.method({
  430. selector: "start",
  431. category: 'action',
  432. fn: function (){
  433. var self=this;
  434. smalltalk.send(smalltalk.send(self,"_current",[]),"_start",[]);
  435. return self},
  436. args: [],
  437. source: "start\x0a\x09self current start",
  438. messageSends: ["start", "current"],
  439. referencedClasses: []
  440. }),
  441. smalltalk.TrappedSingleton.klass);
  442. smalltalk.addClass('Trapped', smalltalk.TrappedSingleton, ['registry'], 'Trapped-Frontend');
  443. smalltalk.addMethod(
  444. "_binder_",
  445. smalltalk.method({
  446. selector: "binder:",
  447. category: 'binders',
  448. fn: function (aTagBrush){
  449. var self=this;
  450. var $1,$2,$3,$5,$4;
  451. var binder;
  452. var tag;
  453. tag=smalltalk.send(smalltalk.send(aTagBrush,"_element",[]),"_nodeName",[]);
  454. $1=smalltalk.send(tag,"__eq",["INPUT"]);
  455. if(smalltalk.assert($1)){
  456. $2=smalltalk.send((smalltalk.TrappedAttrBinder || TrappedAttrBinder),"_new",[]);
  457. smalltalk.send($2,"_attr_",["checked"]);
  458. $3=smalltalk.send($2,"_yourself",[]);
  459. binder=$3;
  460. binder;
  461. };
  462. if(($receiver = binder) == nil || $receiver == undefined){
  463. binder=smalltalk.send((smalltalk.TrappedBinder || TrappedBinder),"_new",[]);
  464. binder;
  465. } else {
  466. binder;
  467. };
  468. smalltalk.send(binder,"_brush_",[aTagBrush]);
  469. $5=smalltalk.send(binder,"_yourself",[]);
  470. $4=$5;
  471. return $4;
  472. },
  473. args: ["aTagBrush"],
  474. source: "binder: aTagBrush\x0a \x22Prototype; will select based on tag etc.\x22\x0a | binder tag |\x0a tag := aTagBrush element nodeName.\x0a tag = 'INPUT' ifTrue: [\x0a \x09binder := TrappedAttrBinder new attr: 'checked'; yourself\x0a ].\x0a binder ifNil: [ binder := TrappedBinder new ].\x0a ^ binder brush: aTagBrush; yourself",
  475. messageSends: ["nodeName", "element", "ifTrue:", "attr:", "new", "yourself", "=", "ifNil:", "brush:"],
  476. referencedClasses: ["TrappedAttrBinder", "TrappedBinder"]
  477. }),
  478. smalltalk.Trapped);
  479. smalltalk.addMethod(
  480. "_byName_",
  481. smalltalk.method({
  482. selector: "byName:",
  483. category: 'accessing',
  484. fn: function (aString){
  485. var self=this;
  486. var $1;
  487. $1=smalltalk.send(self["@registry"],"_at_",[aString]);
  488. return $1;
  489. },
  490. args: ["aString"],
  491. source: "byName: aString\x0a\x09^ registry at: aString",
  492. messageSends: ["at:"],
  493. referencedClasses: []
  494. }),
  495. smalltalk.Trapped);
  496. smalltalk.addMethod(
  497. "_descend_snapshotDo_",
  498. smalltalk.method({
  499. selector: "descend:snapshotDo:",
  500. category: 'action',
  501. fn: function (anArray,aBlock){
  502. var self=this;
  503. var tpsc;
  504. tpsc=smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]);
  505. smalltalk.send(tpsc,"_append_do_",[anArray,(function(){
  506. var path;
  507. var model;
  508. path=smalltalk.send(smalltalk.send(tpsc,"_elements",[]),"_copy",[]);
  509. path;
  510. model=smalltalk.send(self,"_byName_",[smalltalk.send(path,"_first",[])]);
  511. model;
  512. return smalltalk.send(aBlock,"_value_",[smalltalk.send(smalltalk.send((smalltalk.TrappedSnapshot || TrappedSnapshot),"_new",[]),"_path_model_",[path,model])]);
  513. })]);
  514. return self},
  515. args: ["anArray", "aBlock"],
  516. source: "descend: anArray snapshotDo: aBlock\x0a\x09| tpsc |\x0a tpsc := TrappedPathStack current.\x0a tpsc append: anArray do: [\x0a | path model |\x0a path := tpsc elements copy.\x0a \x09 model := self byName: path first.\x0a aBlock value: (TrappedSnapshot new path: path model: model)\x0a ]",
  517. messageSends: ["current", "append:do:", "copy", "elements", "byName:", "first", "value:", "path:model:", "new"],
  518. referencedClasses: ["TrappedPathStack", "TrappedSnapshot"]
  519. }),
  520. smalltalk.Trapped);
  521. smalltalk.addMethod(
  522. "_initialize",
  523. smalltalk.method({
  524. selector: "initialize",
  525. category: 'initialization',
  526. fn: function (){
  527. var self=this;
  528. smalltalk.send(self,"_initialize",[],smalltalk.TrappedSingleton);
  529. self["@registry"]=smalltalk.HashedCollection._fromPairs_([]);
  530. return self},
  531. args: [],
  532. source: "initialize\x0a\x09super initialize.\x0a\x09registry := #{}.",
  533. messageSends: ["initialize"],
  534. referencedClasses: []
  535. }),
  536. smalltalk.Trapped);
  537. smalltalk.addMethod(
  538. "_register_name_",
  539. smalltalk.method({
  540. selector: "register:name:",
  541. category: 'accessing',
  542. fn: function (aFly,aString){
  543. var self=this;
  544. smalltalk.send(self["@registry"],"_at_put_",[aString,aFly]);
  545. return self},
  546. args: ["aFly", "aString"],
  547. source: "register: aFly name: aString\x0a\x09registry at: aString put: aFly",
  548. messageSends: ["at:put:"],
  549. referencedClasses: []
  550. }),
  551. smalltalk.Trapped);
  552. smalltalk.addMethod(
  553. "_start",
  554. smalltalk.method({
  555. selector: "start",
  556. category: 'action',
  557. fn: function (){
  558. var self=this;
  559. var $1;
  560. smalltalk.send(smalltalk.send("[data-trap]","_asJQuery",[]),"_each_",[(function(index,elem){
  561. var trap;
  562. var jq;
  563. var viewName;
  564. var modelName;
  565. var tokens;
  566. var path;
  567. jq=smalltalk.send(elem,"_asJQuery",[]);
  568. jq;
  569. trap=smalltalk.send(jq,"_attr_",["data-trap"]);
  570. trap;
  571. tokens=smalltalk.send(trap,"_tokenize_",[":"]);
  572. tokens;
  573. $1=smalltalk.send(smalltalk.send(tokens,"_size",[]),"__eq",[(1)]);
  574. if(smalltalk.assert($1)){
  575. tokens=smalltalk.send(["TrappedDumbView"],"__comma",[tokens]);
  576. tokens;
  577. };
  578. viewName=smalltalk.send(tokens,"_first",[]);
  579. viewName;
  580. tokens=smalltalk.send(smalltalk.send(smalltalk.send(tokens,"_second",[]),"_tokenize_",[" "]),"_select_",[(function(each){
  581. return smalltalk.send(each,"_notEmpty",[]);
  582. })]);
  583. tokens;
  584. modelName=smalltalk.send(tokens,"_first",[]);
  585. modelName;
  586. path=smalltalk.send((smalltalk.Trapped || Trapped),"_parse_",[smalltalk.send(tokens,"_allButFirst",[])]);
  587. path;
  588. return smalltalk.send(smalltalk.send([modelName],"__comma",[path]),"_trapDescend_",[(function(){
  589. return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Smalltalk || Smalltalk),"_current",[]),"_at_",[viewName]),"_new",[]),"_appendToJQuery_",[jq]);
  590. })]);
  591. })]);
  592. return self},
  593. args: [],
  594. source: "start\x0a\x09'[data-trap]' asJQuery each: [ :index :elem |\x0a \x09| trap jq viewName modelName tokens path |\x0a jq := elem asJQuery.\x0a trap := jq attr: 'data-trap'.\x0a tokens := trap tokenize: ':'.\x0a tokens size = 1 ifTrue: [ tokens := { 'TrappedDumbView' }, tokens ].\x0a viewName := tokens first.\x0a tokens := (tokens second tokenize: ' ') select: [ :each | each notEmpty ].\x0a modelName := tokens first.\x0a path := Trapped parse: tokens allButFirst.\x0a { modelName }, path trapDescend: [(Smalltalk current at: viewName) new appendToJQuery: jq].\x0a ]",
  595. messageSends: ["each:", "asJQuery", "attr:", "tokenize:", "ifTrue:", ",", "=", "size", "first", "select:", "notEmpty", "second", "parse:", "allButFirst", "trapDescend:", "appendToJQuery:", "new", "at:", "current"],
  596. referencedClasses: ["Trapped", "Smalltalk"]
  597. }),
  598. smalltalk.Trapped);
  599. smalltalk.addMethod(
  600. "_parse_",
  601. smalltalk.method({
  602. selector: "parse:",
  603. category: 'accessing',
  604. fn: function (anArray){
  605. var self=this;
  606. var $2,$3,$1;
  607. $1=smalltalk.send(anArray,"_collect_",[(function(each){
  608. var asNum;
  609. asNum = parseInt(each);
  610. ;
  611. $2=smalltalk.send(asNum,"__eq",[asNum]);
  612. if(smalltalk.assert($2)){
  613. return asNum;
  614. } else {
  615. $3=smalltalk.send(smalltalk.send(each,"_first",[]),"__eq",["#"]);
  616. if(smalltalk.assert($3)){
  617. return smalltalk.send(smalltalk.send(each,"_allButFirst",[]),"_asSymbol",[]);
  618. } else {
  619. return each;
  620. };
  621. };
  622. })]);
  623. return $1;
  624. },
  625. args: ["anArray"],
  626. source: "parse: anArray\x0a\x09^anArray collect: [ :each |\x0a \x09| asNum |\x0a \x09<asNum = parseInt(each)>.\x0a asNum = asNum ifTrue: [ asNum ] ifFalse: [\x0a\x09\x09\x09each first = '#' ifTrue: [ each allButFirst asSymbol ] ifFalse: [ each ]]]",
  627. messageSends: ["collect:", "ifTrue:ifFalse:", "asSymbol", "allButFirst", "=", "first"],
  628. referencedClasses: []
  629. }),
  630. smalltalk.Trapped.klass);
  631. smalltalk.addClass('TrappedPathStack', smalltalk.TrappedSingleton, ['elements'], 'Trapped-Frontend');
  632. smalltalk.addMethod(
  633. "_append_do_",
  634. smalltalk.method({
  635. selector: "append:do:",
  636. category: 'descending',
  637. fn: function (anArray,aBlock){
  638. var self=this;
  639. smalltalk.send(self,"_with_do_",[smalltalk.send(self["@elements"],"__comma",[anArray]),aBlock]);
  640. return self},
  641. args: ["anArray", "aBlock"],
  642. source: "append: anArray do: aBlock\x0a self with: elements, anArray do: aBlock",
  643. messageSends: ["with:do:", ","],
  644. referencedClasses: []
  645. }),
  646. smalltalk.TrappedPathStack);
  647. smalltalk.addMethod(
  648. "_elements",
  649. smalltalk.method({
  650. selector: "elements",
  651. category: 'accessing',
  652. fn: function (){
  653. var self=this;
  654. return self["@elements"];
  655. },
  656. args: [],
  657. source: "elements\x0a\x09^elements",
  658. messageSends: [],
  659. referencedClasses: []
  660. }),
  661. smalltalk.TrappedPathStack);
  662. smalltalk.addMethod(
  663. "_initialize",
  664. smalltalk.method({
  665. selector: "initialize",
  666. category: 'initialization',
  667. fn: function (){
  668. var self=this;
  669. smalltalk.send(self,"_initialize",[],smalltalk.TrappedSingleton);
  670. self["@elements"]=[];
  671. return self},
  672. args: [],
  673. source: "initialize\x0a super initialize.\x0a\x09elements := #().",
  674. messageSends: ["initialize"],
  675. referencedClasses: []
  676. }),
  677. smalltalk.TrappedPathStack);
  678. smalltalk.addMethod(
  679. "_with_do_",
  680. smalltalk.method({
  681. selector: "with:do:",
  682. category: 'descending',
  683. fn: function (anArray,aBlock){
  684. var self=this;
  685. var old;
  686. old=self["@elements"];
  687. smalltalk.send((function(){
  688. self["@elements"]=anArray;
  689. self["@elements"];
  690. return smalltalk.send(aBlock,"_value",[]);
  691. }),"_ensure_",[(function(){
  692. self["@elements"]=old;
  693. return self["@elements"];
  694. })]);
  695. return self},
  696. args: ["anArray", "aBlock"],
  697. source: "with: anArray do: aBlock\x0a\x09| old |\x0a old := elements.\x0a [ elements := anArray.\x0a\x09aBlock value ] ensure: [ elements := old ]",
  698. messageSends: ["ensure:", "value"],
  699. referencedClasses: []
  700. }),
  701. smalltalk.TrappedPathStack);
  702. smalltalk.addClass('TrappedSnapshot', smalltalk.Object, ['path', 'model'], 'Trapped-Frontend');
  703. smalltalk.addMethod(
  704. "_do_",
  705. smalltalk.method({
  706. selector: "do:",
  707. category: 'action',
  708. fn: function (aBlock){
  709. var self=this;
  710. smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_with_do_",[self["@path"],(function(){
  711. return smalltalk.send(aBlock,"_value_",[self["@model"]]);
  712. })]);
  713. return self},
  714. args: ["aBlock"],
  715. source: "do: aBlock\x0a\x09TrappedPathStack current with: path do: [ aBlock value: model ]",
  716. messageSends: ["with:do:", "value:", "current"],
  717. referencedClasses: ["TrappedPathStack"]
  718. }),
  719. smalltalk.TrappedSnapshot);
  720. smalltalk.addMethod(
  721. "_model",
  722. smalltalk.method({
  723. selector: "model",
  724. category: 'accessing',
  725. fn: function (){
  726. var self=this;
  727. return self["@model"];
  728. },
  729. args: [],
  730. source: "model\x0a\x09^model",
  731. messageSends: [],
  732. referencedClasses: []
  733. }),
  734. smalltalk.TrappedSnapshot);
  735. smalltalk.addMethod(
  736. "_modify_",
  737. smalltalk.method({
  738. selector: "modify:",
  739. category: 'action',
  740. fn: function (aBlock){
  741. var self=this;
  742. smalltalk.send(smalltalk.send(self,"_model",[]),"_modify_do_",[smalltalk.send(smalltalk.send(self,"_path",[]),"_allButFirst",[]),aBlock]);
  743. return self},
  744. args: ["aBlock"],
  745. source: "modify: aBlock\x0a\x09self model modify: self path allButFirst do: aBlock",
  746. messageSends: ["modify:do:", "allButFirst", "path", "model"],
  747. referencedClasses: []
  748. }),
  749. smalltalk.TrappedSnapshot);
  750. smalltalk.addMethod(
  751. "_path",
  752. smalltalk.method({
  753. selector: "path",
  754. category: 'accessing',
  755. fn: function (){
  756. var self=this;
  757. return self["@path"];
  758. },
  759. args: [],
  760. source: "path\x0a\x09^path",
  761. messageSends: [],
  762. referencedClasses: []
  763. }),
  764. smalltalk.TrappedSnapshot);
  765. smalltalk.addMethod(
  766. "_path_model_",
  767. smalltalk.method({
  768. selector: "path:model:",
  769. category: 'accessing',
  770. fn: function (anArray,aTrappedMW){
  771. var self=this;
  772. self["@path"]=anArray;
  773. self["@model"]=aTrappedMW;
  774. return self},
  775. args: ["anArray", "aTrappedMW"],
  776. source: "path: anArray model: aTrappedMW\x0a\x09path := anArray.\x0a model := aTrappedMW",
  777. messageSends: [],
  778. referencedClasses: []
  779. }),
  780. smalltalk.TrappedSnapshot);
  781. smalltalk.addClass('TrappedSubscription', smalltalk.KeyedSubscriptionBase, [], 'Trapped-Frontend');
  782. smalltalk.addMethod(
  783. "_accepts_",
  784. smalltalk.method({
  785. selector: "accepts:",
  786. category: 'testing',
  787. fn: function (aKey){
  788. var self=this;
  789. var $1;
  790. $1=smalltalk.send(smalltalk.send(smalltalk.send(aKey,"_size",[]),"__lt_eq",[smalltalk.send(self["@key"],"_size",[])]),"_and_",[(function(){
  791. return smalltalk.send(aKey,"__eq",[smalltalk.send(self["@key"],"_copyFrom_to_",[(1),smalltalk.send(aKey,"_size",[])])]);
  792. })]);
  793. return $1;
  794. },
  795. args: ["aKey"],
  796. source: "accepts: aKey\x0a ^aKey size <= key size and: [aKey = (key copyFrom: 1 to: aKey size)]",
  797. messageSends: ["and:", "=", "copyFrom:to:", "size", "<="],
  798. referencedClasses: []
  799. }),
  800. smalltalk.TrappedSubscription);
  801. smalltalk.addMethod(
  802. "_trapDescend_",
  803. smalltalk.method({
  804. selector: "trapDescend:",
  805. category: '*Trapped-Frontend',
  806. fn: function (aBlock){
  807. var self=this;
  808. smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_descend_snapshotDo_",[self,aBlock]);
  809. return self},
  810. args: ["aBlock"],
  811. source: "trapDescend: aBlock\x0a\x09Trapped current descend: self snapshotDo: aBlock",
  812. messageSends: ["descend:snapshotDo:", "current"],
  813. referencedClasses: ["Trapped"]
  814. }),
  815. smalltalk.Array);
  816. smalltalk.addMethod(
  817. "_trapDescend_",
  818. smalltalk.method({
  819. selector: "trapDescend:",
  820. category: '*Trapped-Frontend',
  821. fn: function (aBlock){
  822. var self=this;
  823. smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_descend_snapshotDo_",[self,aBlock]);
  824. return self},
  825. args: ["aBlock"],
  826. source: "trapDescend: aBlock\x0a\x09Trapped current descend: self snapshotDo: aBlock",
  827. messageSends: ["descend:snapshotDo:", "current"],
  828. referencedClasses: ["Trapped"]
  829. }),
  830. smalltalk.Array);
  831. smalltalk.addMethod(
  832. "_trap_",
  833. smalltalk.method({
  834. selector: "trap:",
  835. category: '*Trapped-Frontend',
  836. fn: function (path){
  837. var self=this;
  838. smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_binder_",[self]),"_installFor_",[path]);
  839. return self},
  840. args: ["path"],
  841. source: "trap: path\x0a\x09(Trapped current binder: self) installFor: path",
  842. messageSends: ["installFor:", "binder:", "current"],
  843. referencedClasses: ["Trapped"]
  844. }),
  845. smalltalk.TagBrush);
  846. smalltalk.addMethod(
  847. "_trap_read_",
  848. smalltalk.method({
  849. selector: "trap:read:",
  850. category: '*Trapped-Frontend',
  851. fn: function (path,aBlock){
  852. var self=this;
  853. var $1;
  854. smalltalk.send(path,"_trapDescend_",[(function(snap){
  855. return smalltalk.send(smalltalk.send(snap,"_model",[]),"_watch_do_",[smalltalk.send(smalltalk.send(snap,"_path",[]),"_allButFirst",[]),(function(data){
  856. $1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_closest_",["html"]),"_toArray",[]),"_isEmpty",[]);
  857. if(smalltalk.assert($1)){
  858. smalltalk.send((smalltalk.KeyedPubSubUnsubscribe || KeyedPubSubUnsubscribe),"_signal",[]);
  859. };
  860. return smalltalk.send(snap,"_do_",[(function(){
  861. return smalltalk.send(self,"_with_",[(function(html){
  862. return smalltalk.send(aBlock,"_value_value_",[data,html]);
  863. })]);
  864. })]);
  865. })]);
  866. })]);
  867. return self},
  868. args: ["path", "aBlock"],
  869. source: "trap: path read: aBlock\x0a\x09path trapDescend: [ :snap |\x0a snap model watch: snap path allButFirst do: [ :data |\x0a (self asJQuery closest: 'html') toArray isEmpty ifTrue: [ KeyedPubSubUnsubscribe signal ].\x0a \x09snap do: [ self with: [ :html | aBlock value: data value: html ] ]\x0a \x09]\x0a ]",
  870. messageSends: ["trapDescend:", "watch:do:", "allButFirst", "path", "ifTrue:", "signal", "isEmpty", "toArray", "closest:", "asJQuery", "do:", "with:", "value:value:", "model"],
  871. referencedClasses: ["KeyedPubSubUnsubscribe"]
  872. }),
  873. smalltalk.TagBrush);
  874. smalltalk.addMethod(
  875. "_trap_toggle_",
  876. smalltalk.method({
  877. selector: "trap:toggle:",
  878. category: '*Trapped-Frontend',
  879. fn: function (path,aBlock){
  880. var self=this;
  881. smalltalk.send(self,"_trap_toggle_ifNotPresent_",[path,aBlock,(function(){
  882. return smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_hide",[]);
  883. })]);
  884. return self},
  885. args: ["path", "aBlock"],
  886. source: "trap: path toggle: aBlock\x0a self trap: path toggle: aBlock ifNotPresent: [ self asJQuery hide ]",
  887. messageSends: ["trap:toggle:ifNotPresent:", "hide", "asJQuery"],
  888. referencedClasses: []
  889. }),
  890. smalltalk.TagBrush);
  891. smalltalk.addMethod(
  892. "_trap_toggle_ifNotPresent_",
  893. smalltalk.method({
  894. selector: "trap:toggle:ifNotPresent:",
  895. category: '*Trapped-Frontend',
  896. fn: function (path,aBlock,anotherBlock){
  897. var self=this;
  898. var $1,$2,$3,$4;
  899. var shown;
  900. shown=nil;
  901. smalltalk.send(self,"_trap_read_",[path,(function(data,html){
  902. $1=smalltalk.send(shown,"__eq",[smalltalk.send(data,"_notNil",[])]);
  903. if(! smalltalk.assert($1)){
  904. shown=smalltalk.send(data,"_notNil",[]);
  905. shown;
  906. $2=smalltalk.send(self,"_asJQuery",[]);
  907. smalltalk.send($2,"_empty",[]);
  908. $3=smalltalk.send($2,"_show",[]);
  909. $3;
  910. if(smalltalk.assert(shown)){
  911. $4=aBlock;
  912. } else {
  913. $4=anotherBlock;
  914. };
  915. return smalltalk.send($4,"_value_value_",[data,html]);
  916. };
  917. })]);
  918. return self},
  919. args: ["path", "aBlock", "anotherBlock"],
  920. source: "trap: path toggle: aBlock ifNotPresent: anotherBlock\x0a | shown |\x0a shown := nil.\x0a self trap: path read: [ :data : html |\x0a shown = data notNil ifFalse: [\x0a shown := data notNil.\x0a self asJQuery empty; show.\x0a (shown ifTrue: [aBlock] ifFalse: [anotherBlock]) value: data value: html.\x0a ]\x0a ]",
  921. messageSends: ["trap:read:", "ifFalse:", "notNil", "empty", "asJQuery", "show", "value:value:", "ifTrue:ifFalse:", "="],
  922. referencedClasses: []
  923. }),
  924. smalltalk.TagBrush);
  925. smalltalk.addMethod(
  926. "_trapIter_tag_do_",
  927. smalltalk.method({
  928. selector: "trapIter:tag:do:",
  929. category: '*Trapped-Frontend',
  930. fn: function (path,aSymbol,aBlock){
  931. var self=this;
  932. smalltalk.send(self,"_trap_read_",[path,(function(model,html){
  933. smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
  934. if(($receiver = model) == nil || $receiver == undefined){
  935. return model;
  936. } else {
  937. return smalltalk.send(model,"_withIndexDo_",[(function(item,i){
  938. return smalltalk.send(smalltalk.send(html,"_perform_",[aSymbol]),"_trap_read_",[[i],aBlock]);
  939. })]);
  940. };
  941. })]);
  942. return self},
  943. args: ["path", "aSymbol", "aBlock"],
  944. source: "trapIter: path tag: aSymbol do: aBlock\x0a self trap: path read: [ :model :html |\x0a html root empty.\x0a model ifNotNil: [ model withIndexDo: [ :item :i |\x0a (html perform: aSymbol) trap: {i} read: aBlock\x0a ]]\x0a ]",
  945. messageSends: ["trap:read:", "empty", "root", "ifNotNil:", "withIndexDo:", "perform:"],
  946. referencedClasses: []
  947. }),
  948. smalltalk.TagBrush);