Trapped-Frontend.js 30 KB

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