Trapped-Frontend.js 31 KB

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