Trapped-Frontend.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. smalltalk.addPackage('Trapped-Frontend', {});
  2. smalltalk.addClass('TrappedDispatcher', smalltalk.KeyedPubSubBase, [], 'Trapped-Frontend');
  3. 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"
  4. smalltalk.addMethod(
  5. "_subscriptionKey_block_",
  6. smalltalk.method({
  7. selector: "subscriptionKey:block:",
  8. category: 'action',
  9. fn: function (key,aBlock){
  10. var self=this;
  11. var $2,$3,$1;
  12. $2=smalltalk.send((smalltalk.TrappedSubscription || TrappedSubscription),"_new",[]);
  13. smalltalk.send($2,"_key_block_",[key,aBlock]);
  14. $3=smalltalk.send($2,"_yourself",[]);
  15. $1=$3;
  16. return $1;
  17. },
  18. args: ["key", "aBlock"],
  19. source: "subscriptionKey: key block: aBlock\x0a\x09^TrappedSubscription new key: key block: aBlock; yourself\x0a",
  20. messageSends: ["key:block:", "new", "yourself"],
  21. referencedClasses: ["TrappedSubscription"]
  22. }),
  23. smalltalk.TrappedDispatcher);
  24. smalltalk.addClass('TrappedDumbView', smalltalk.Widget, [], 'Trapped-Frontend');
  25. smalltalk.TrappedDumbView.comment="I just read and show an actual path."
  26. smalltalk.addMethod(
  27. "_renderOn_",
  28. smalltalk.method({
  29. selector: "renderOn:",
  30. category: 'rendering',
  31. fn: function (html){
  32. var self=this;
  33. smalltalk.send(smalltalk.send(html,"_root",[]),"_trapShow_",[[]]);
  34. return self},
  35. args: ["html"],
  36. source: "renderOn: html\x0a\x09html root trapShow: #()",
  37. messageSends: ["trapShow:", "root"],
  38. referencedClasses: []
  39. }),
  40. smalltalk.TrappedDumbView);
  41. smalltalk.addClass('TrappedModelWrapper', smalltalk.Object, ['dispatcher', 'payload'], 'Trapped-Frontend');
  42. 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"
  43. smalltalk.addMethod(
  44. "_dispatcher",
  45. smalltalk.method({
  46. selector: "dispatcher",
  47. category: 'accessing',
  48. fn: function (){
  49. var self=this;
  50. return self["@dispatcher"];
  51. },
  52. args: [],
  53. source: "dispatcher\x0a\x09^dispatcher",
  54. messageSends: [],
  55. referencedClasses: []
  56. }),
  57. smalltalk.TrappedModelWrapper);
  58. smalltalk.addMethod(
  59. "_dispatcher_",
  60. smalltalk.method({
  61. selector: "dispatcher:",
  62. category: 'accessing',
  63. fn: function (aDispatcher){
  64. var self=this;
  65. self["@dispatcher"]=aDispatcher;
  66. return self},
  67. args: ["aDispatcher"],
  68. source: "dispatcher: aDispatcher\x0a\x09dispatcher := aDispatcher",
  69. messageSends: [],
  70. referencedClasses: []
  71. }),
  72. smalltalk.TrappedModelWrapper);
  73. smalltalk.addMethod(
  74. "_model_",
  75. smalltalk.method({
  76. selector: "model:",
  77. category: 'accessing',
  78. fn: function (anObject){
  79. var self=this;
  80. self["@payload"]=anObject;
  81. smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[[]]);
  82. return self},
  83. args: ["anObject"],
  84. source: "model: anObject\x0a\x09payload := anObject.\x0a self dispatcher changed: #()",
  85. messageSends: ["changed:", "dispatcher"],
  86. referencedClasses: []
  87. }),
  88. smalltalk.TrappedModelWrapper);
  89. smalltalk.addMethod(
  90. "_name",
  91. smalltalk.method({
  92. selector: "name",
  93. category: 'accessing',
  94. fn: function (){
  95. var self=this;
  96. var $1;
  97. $1=smalltalk.send(smalltalk.send(self,"_class",[]),"_name",[]);
  98. return $1;
  99. },
  100. args: [],
  101. source: "name\x0a\x09^ self class name",
  102. messageSends: ["name", "class"],
  103. referencedClasses: []
  104. }),
  105. smalltalk.TrappedModelWrapper);
  106. smalltalk.addMethod(
  107. "_start",
  108. smalltalk.method({
  109. selector: "start",
  110. category: 'action',
  111. fn: function (){
  112. var self=this;
  113. smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_register_name_",[self,smalltalk.send(self,"_name",[])]);
  114. return self},
  115. args: [],
  116. source: "start\x0a\x09Trapped current register: self name: self name",
  117. messageSends: ["register:name:", "name", "current"],
  118. referencedClasses: ["Trapped"]
  119. }),
  120. smalltalk.TrappedModelWrapper);
  121. smalltalk.addMethod(
  122. "_watch_do_",
  123. smalltalk.method({
  124. selector: "watch:do:",
  125. category: 'action',
  126. fn: function (path,aBlock){
  127. var self=this;
  128. smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_on_hook_",[path,(function(){
  129. return smalltalk.send(self,"_read_do_",[path,aBlock]);
  130. })]);
  131. return self},
  132. args: ["path", "aBlock"],
  133. source: "watch: path do: aBlock\x0a\x09self dispatcher on: path hook: [ self read: path do: aBlock ]\x0a",
  134. messageSends: ["on:hook:", "read:do:", "dispatcher"],
  135. referencedClasses: []
  136. }),
  137. smalltalk.TrappedModelWrapper);
  138. smalltalk.addMethod(
  139. "_start",
  140. smalltalk.method({
  141. selector: "start",
  142. category: 'action',
  143. fn: function (){
  144. var self=this;
  145. var $2,$3,$1;
  146. $2=smalltalk.send(self,"_new",[]);
  147. smalltalk.send($2,"_start",[]);
  148. $3=smalltalk.send($2,"_yourself",[]);
  149. $1=$3;
  150. return $1;
  151. },
  152. args: [],
  153. source: "start\x0a\x09^self new start; yourself",
  154. messageSends: ["start", "new", "yourself"],
  155. referencedClasses: []
  156. }),
  157. smalltalk.TrappedModelWrapper.klass);
  158. smalltalk.addClass('TrappedMWDirect', smalltalk.TrappedModelWrapper, [], 'Trapped-Frontend');
  159. smalltalk.TrappedMWDirect.comment="I am TrappedModelWrapper that directly manipulate\x0athe object passed to model:"
  160. smalltalk.addMethod(
  161. "_modify_do_",
  162. smalltalk.method({
  163. selector: "modify:do:",
  164. category: 'action',
  165. fn: function (path,aBlock){
  166. var self=this;
  167. var newValue;
  168. var eavModel;
  169. eavModel=smalltalk.send(path,"_asEavModel",[]);
  170. newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[self["@payload"]])]);
  171. smalltalk.send((function(){
  172. return smalltalk.send(eavModel,"_on_put_",[self["@payload"],newValue]);
  173. }),"_ensure_",[(function(){
  174. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  175. })]);
  176. return self},
  177. args: ["path", "aBlock"],
  178. 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",
  179. messageSends: ["asEavModel", "value:", "on:", "ensure:", "changed:", "dispatcher", "on:put:"],
  180. referencedClasses: []
  181. }),
  182. smalltalk.TrappedMWDirect);
  183. smalltalk.addMethod(
  184. "_read_do_",
  185. smalltalk.method({
  186. selector: "read:do:",
  187. category: 'action',
  188. fn: function (path,aBlock){
  189. var self=this;
  190. var eavModel;
  191. eavModel=smalltalk.send(path,"_asEavModel",[]);
  192. smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[self["@payload"]])]);
  193. return self},
  194. args: ["path", "aBlock"],
  195. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: payload)\x0a",
  196. messageSends: ["asEavModel", "value:", "on:"],
  197. referencedClasses: []
  198. }),
  199. smalltalk.TrappedMWDirect);
  200. smalltalk.addClass('TrappedMWIsolated', smalltalk.TrappedModelWrapper, [], 'Trapped-Frontend');
  201. smalltalk.TrappedMWIsolated.comment="I am TrappedModelWrapper than wrap access\x0ato an object passed to model: via Isolator."
  202. smalltalk.addMethod(
  203. "_model_",
  204. smalltalk.method({
  205. selector: "model:",
  206. category: 'accessing',
  207. fn: function (anObject){
  208. var self=this;
  209. smalltalk.send(self,"_model_",[smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[anObject])],smalltalk.TrappedModelWrapper);
  210. return self},
  211. args: ["anObject"],
  212. source: "model: anObject\x0a\x09super model: (Isolator on: anObject)",
  213. messageSends: ["model:", "on:"],
  214. referencedClasses: ["Isolator"]
  215. }),
  216. smalltalk.TrappedMWIsolated);
  217. smalltalk.addMethod(
  218. "_modify_do_",
  219. smalltalk.method({
  220. selector: "modify:do:",
  221. category: 'action',
  222. fn: function (path,aBlock){
  223. var self=this;
  224. var eavModel;
  225. eavModel=smalltalk.send(smalltalk.send([smalltalk.symbolFor("root")],"__comma",[path]),"_asEavModel",[]);
  226. smalltalk.send((function(){
  227. return smalltalk.send(self["@payload"],"_model_modify_",[eavModel,aBlock]);
  228. }),"_ensure_",[(function(){
  229. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  230. })]);
  231. return self},
  232. args: ["path", "aBlock"],
  233. source: "modify: path do: aBlock\x0a | eavModel |\x0a eavModel := ({#root},path) asEavModel.\x0a [ payload model: eavModel modify: aBlock ] ensure: [ self dispatcher changed: path ]\x0a",
  234. messageSends: ["asEavModel", ",", "ensure:", "changed:", "dispatcher", "model:modify:"],
  235. referencedClasses: []
  236. }),
  237. smalltalk.TrappedMWIsolated);
  238. smalltalk.addMethod(
  239. "_read_do_",
  240. smalltalk.method({
  241. selector: "read:do:",
  242. category: 'action',
  243. fn: function (path,aBlock){
  244. var self=this;
  245. var eavModel;
  246. eavModel=smalltalk.send(smalltalk.send([smalltalk.symbolFor("root")],"__comma",[path]),"_asEavModel",[]);
  247. smalltalk.send(self["@payload"],"_model_read_",[eavModel,aBlock]);
  248. return self},
  249. args: ["path", "aBlock"],
  250. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := ({#root},path) asEavModel.\x0a payload model: eavModel read: aBlock\x0a",
  251. messageSends: ["asEavModel", ",", "model:read:"],
  252. referencedClasses: []
  253. }),
  254. smalltalk.TrappedMWIsolated);
  255. smalltalk.addClass('TrappedSingleton', smalltalk.Object, [], 'Trapped-Frontend');
  256. smalltalk.addMethod(
  257. "_start",
  258. smalltalk.method({
  259. selector: "start",
  260. category: 'action',
  261. fn: function (){
  262. var self=this;
  263. var $1;
  264. $1=smalltalk.send(self,"_subclassResponsibility",[]);
  265. return $1;
  266. },
  267. args: [],
  268. source: "start\x0a\x09^ self subclassResponsibility",
  269. messageSends: ["subclassResponsibility"],
  270. referencedClasses: []
  271. }),
  272. smalltalk.TrappedSingleton);
  273. smalltalk.TrappedSingleton.klass.iVarNames = ['current'];
  274. smalltalk.addMethod(
  275. "_current",
  276. smalltalk.method({
  277. selector: "current",
  278. category: 'accessing',
  279. fn: function (){
  280. var self=this;
  281. var $1;
  282. if(($receiver = self["@current"]) == nil || $receiver == undefined){
  283. self["@current"]=smalltalk.send(self,"_new",[]);
  284. $1=self["@current"];
  285. } else {
  286. $1=self["@current"];
  287. };
  288. return $1;
  289. },
  290. args: [],
  291. source: "current\x0a\x09^ current ifNil: [ current := self new ]",
  292. messageSends: ["ifNil:", "new"],
  293. referencedClasses: []
  294. }),
  295. smalltalk.TrappedSingleton.klass);
  296. smalltalk.addMethod(
  297. "_start",
  298. smalltalk.method({
  299. selector: "start",
  300. category: 'action',
  301. fn: function (){
  302. var self=this;
  303. smalltalk.send(smalltalk.send(self,"_current",[]),"_start",[]);
  304. return self},
  305. args: [],
  306. source: "start\x0a\x09self current start",
  307. messageSends: ["start", "current"],
  308. referencedClasses: []
  309. }),
  310. smalltalk.TrappedSingleton.klass);
  311. smalltalk.addClass('Trapped', smalltalk.TrappedSingleton, ['registry'], 'Trapped-Frontend');
  312. smalltalk.addMethod(
  313. "_byName_",
  314. smalltalk.method({
  315. selector: "byName:",
  316. category: 'accessing',
  317. fn: function (aString){
  318. var self=this;
  319. var $1;
  320. $1=smalltalk.send(self["@registry"],"_at_",[aString]);
  321. return $1;
  322. },
  323. args: ["aString"],
  324. source: "byName: aString\x0a\x09^ registry at: aString",
  325. messageSends: ["at:"],
  326. referencedClasses: []
  327. }),
  328. smalltalk.Trapped);
  329. smalltalk.addMethod(
  330. "_initialize",
  331. smalltalk.method({
  332. selector: "initialize",
  333. category: 'initialization',
  334. fn: function (){
  335. var self=this;
  336. smalltalk.send(self,"_initialize",[],smalltalk.TrappedSingleton);
  337. self["@registry"]=smalltalk.HashedCollection._fromPairs_([]);
  338. return self},
  339. args: [],
  340. source: "initialize\x0a\x09super initialize.\x0a\x09registry := #{}.",
  341. messageSends: ["initialize"],
  342. referencedClasses: []
  343. }),
  344. smalltalk.Trapped);
  345. smalltalk.addMethod(
  346. "_register_name_",
  347. smalltalk.method({
  348. selector: "register:name:",
  349. category: 'accessing',
  350. fn: function (aFly,aString){
  351. var self=this;
  352. smalltalk.send(self["@registry"],"_at_put_",[aString,aFly]);
  353. return self},
  354. args: ["aFly", "aString"],
  355. source: "register: aFly name: aString\x0a\x09registry at: aString put: aFly",
  356. messageSends: ["at:put:"],
  357. referencedClasses: []
  358. }),
  359. smalltalk.Trapped);
  360. smalltalk.addMethod(
  361. "_start",
  362. smalltalk.method({
  363. selector: "start",
  364. category: 'action',
  365. fn: function (){
  366. var self=this;
  367. var $1;
  368. smalltalk.send(smalltalk.send("[data-trap]","_asJQuery",[]),"_each_",[(function(index,elem){
  369. var trap;
  370. var jq;
  371. var viewName;
  372. var modelName;
  373. var tokens;
  374. var path;
  375. jq=smalltalk.send(elem,"_asJQuery",[]);
  376. jq;
  377. trap=smalltalk.send(jq,"_attr_",["data-trap"]);
  378. trap;
  379. tokens=smalltalk.send(trap,"_tokenize_",[":"]);
  380. tokens;
  381. $1=smalltalk.send(smalltalk.send(tokens,"_size",[]),"__eq",[(1)]);
  382. if(smalltalk.assert($1)){
  383. tokens=smalltalk.send(["TrappedDumbView"],"__comma",[tokens]);
  384. tokens;
  385. };
  386. viewName=smalltalk.send(tokens,"_first",[]);
  387. viewName;
  388. tokens=smalltalk.send(smalltalk.send(smalltalk.send(tokens,"_second",[]),"_tokenize_",[" "]),"_select_",[(function(each){
  389. return smalltalk.send(each,"_notEmpty",[]);
  390. })]);
  391. tokens;
  392. modelName=smalltalk.send(tokens,"_first",[]);
  393. modelName;
  394. path=smalltalk.send((smalltalk.Trapped || Trapped),"_parse_",[smalltalk.send(tokens,"_allButFirst",[])]);
  395. path;
  396. return smalltalk.send(smalltalk.send([modelName],"__comma",[path]),"_trapDescend_",[(function(){
  397. return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Smalltalk || Smalltalk),"_current",[]),"_at_",[viewName]),"_new",[]),"_appendToJQuery_",[jq]);
  398. })]);
  399. })]);
  400. return self},
  401. args: [],
  402. 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 ]",
  403. messageSends: ["each:", "asJQuery", "attr:", "tokenize:", "ifTrue:", ",", "=", "size", "first", "select:", "notEmpty", "second", "parse:", "allButFirst", "trapDescend:", "appendToJQuery:", "new", "at:", "current"],
  404. referencedClasses: ["Trapped", "Smalltalk"]
  405. }),
  406. smalltalk.Trapped);
  407. smalltalk.addMethod(
  408. "_parse_",
  409. smalltalk.method({
  410. selector: "parse:",
  411. category: 'accessing',
  412. fn: function (anArray){
  413. var self=this;
  414. var $2,$3,$1;
  415. $1=smalltalk.send(anArray,"_collect_",[(function(each){
  416. var asNum;
  417. asNum = parseInt(each);
  418. ;
  419. $2=smalltalk.send(asNum,"__eq",[asNum]);
  420. if(smalltalk.assert($2)){
  421. return asNum;
  422. } else {
  423. $3=smalltalk.send(smalltalk.send(each,"_first",[]),"__eq",["#"]);
  424. if(smalltalk.assert($3)){
  425. return smalltalk.send(smalltalk.send(each,"_allButFirst",[]),"_asSymbol",[]);
  426. } else {
  427. return each;
  428. };
  429. };
  430. })]);
  431. return $1;
  432. },
  433. args: ["anArray"],
  434. 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 ]]]",
  435. messageSends: ["collect:", "ifTrue:ifFalse:", "asSymbol", "allButFirst", "=", "first"],
  436. referencedClasses: []
  437. }),
  438. smalltalk.Trapped.klass);
  439. smalltalk.addMethod(
  440. "_path",
  441. smalltalk.method({
  442. selector: "path",
  443. category: 'accessing',
  444. fn: function (){
  445. var self=this;
  446. var $1;
  447. $1=smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_elements",[]);
  448. return $1;
  449. },
  450. args: [],
  451. source: "path\x0a\x09^TrappedPathStack current elements",
  452. messageSends: ["elements", "current"],
  453. referencedClasses: ["TrappedPathStack"]
  454. }),
  455. smalltalk.Trapped.klass);
  456. smalltalk.addClass('TrappedPathStack', smalltalk.TrappedSingleton, ['elements'], 'Trapped-Frontend');
  457. smalltalk.addMethod(
  458. "_append_",
  459. smalltalk.method({
  460. selector: "append:",
  461. category: 'descending',
  462. fn: function (anArray){
  463. var self=this;
  464. self["@elements"]=smalltalk.send(self["@elements"],"__comma",[anArray]);
  465. return self},
  466. args: ["anArray"],
  467. source: "append: anArray\x0a elements := elements, anArray",
  468. messageSends: [","],
  469. referencedClasses: []
  470. }),
  471. smalltalk.TrappedPathStack);
  472. smalltalk.addMethod(
  473. "_elements",
  474. smalltalk.method({
  475. selector: "elements",
  476. category: 'accessing',
  477. fn: function (){
  478. var self=this;
  479. return self["@elements"];
  480. },
  481. args: [],
  482. source: "elements\x0a\x09^elements",
  483. messageSends: [],
  484. referencedClasses: []
  485. }),
  486. smalltalk.TrappedPathStack);
  487. smalltalk.addMethod(
  488. "_initialize",
  489. smalltalk.method({
  490. selector: "initialize",
  491. category: 'initialization',
  492. fn: function (){
  493. var self=this;
  494. smalltalk.send(self,"_initialize",[],smalltalk.TrappedSingleton);
  495. self["@elements"]=[];
  496. return self},
  497. args: [],
  498. source: "initialize\x0a super initialize.\x0a\x09elements := #().",
  499. messageSends: ["initialize"],
  500. referencedClasses: []
  501. }),
  502. smalltalk.TrappedPathStack);
  503. smalltalk.addMethod(
  504. "_with_do_",
  505. smalltalk.method({
  506. selector: "with:do:",
  507. category: 'descending',
  508. fn: function (anArray,aBlock){
  509. var self=this;
  510. var old;
  511. old=self["@elements"];
  512. smalltalk.send((function(){
  513. smalltalk.send(self,"_append_",[anArray]);
  514. return smalltalk.send(aBlock,"_value",[]);
  515. }),"_ensure_",[(function(){
  516. self["@elements"]=old;
  517. return self["@elements"];
  518. })]);
  519. return self},
  520. args: ["anArray", "aBlock"],
  521. source: "with: anArray do: aBlock\x0a\x09| old |\x0a old := elements.\x0a [ self append: anArray.\x0a\x09aBlock value ] ensure: [ elements := old ]",
  522. messageSends: ["ensure:", "append:", "value"],
  523. referencedClasses: []
  524. }),
  525. smalltalk.TrappedPathStack);
  526. smalltalk.addClass('TrappedSubscription', smalltalk.KeyedSubscriptionBase, [], 'Trapped-Frontend');
  527. smalltalk.addMethod(
  528. "_accepts_",
  529. smalltalk.method({
  530. selector: "accepts:",
  531. category: 'testing',
  532. fn: function (aKey){
  533. var self=this;
  534. var $1;
  535. $1=smalltalk.send(smalltalk.send(smalltalk.send(aKey,"_size",[]),"__lt_eq",[smalltalk.send(self["@key"],"_size",[])]),"_and_",[(function(){
  536. return smalltalk.send(aKey,"__eq",[smalltalk.send(self["@key"],"_copyFrom_to_",[(1),smalltalk.send(aKey,"_size",[])])]);
  537. })]);
  538. return $1;
  539. },
  540. args: ["aKey"],
  541. source: "accepts: aKey\x0a ^aKey size <= key size and: [aKey = (key copyFrom: 1 to: aKey size)]",
  542. messageSends: ["and:", "=", "copyFrom:to:", "size", "<="],
  543. referencedClasses: []
  544. }),
  545. smalltalk.TrappedSubscription);
  546. smalltalk.addMethod(
  547. "_trapDescend_",
  548. smalltalk.method({
  549. selector: "trapDescend:",
  550. category: '*Trapped-Frontend',
  551. fn: function (aBlock){
  552. var self=this;
  553. smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_with_do_",[self,aBlock]);
  554. return self},
  555. args: ["aBlock"],
  556. source: "trapDescend: aBlock\x0a\x09TrappedPathStack current with: self do: aBlock",
  557. messageSends: ["with:do:", "current"],
  558. referencedClasses: ["TrappedPathStack"]
  559. }),
  560. smalltalk.Array);
  561. smalltalk.addMethod(
  562. "_trapDescend_",
  563. smalltalk.method({
  564. selector: "trapDescend:",
  565. category: '*Trapped-Frontend',
  566. fn: function (aBlock){
  567. var self=this;
  568. smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_with_do_",[self,aBlock]);
  569. return self},
  570. args: ["aBlock"],
  571. source: "trapDescend: aBlock\x0a\x09TrappedPathStack current with: self do: aBlock",
  572. messageSends: ["with:do:", "current"],
  573. referencedClasses: ["TrappedPathStack"]
  574. }),
  575. smalltalk.Array);
  576. smalltalk.addMethod(
  577. "_trap_read_",
  578. smalltalk.method({
  579. selector: "trap:read:",
  580. category: '*Trapped-Frontend',
  581. fn: function (path,aBlock){
  582. var self=this;
  583. var $1;
  584. smalltalk.send(path,"_trapDescend_",[(function(){
  585. var actual;
  586. var model;
  587. actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
  588. actual;
  589. model=smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_byName_",[smalltalk.send(actual,"_first",[])]);
  590. model;
  591. return smalltalk.send(model,"_watch_do_",[smalltalk.send(actual,"_allButFirst",[]),(function(data){
  592. $1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_closest_",["html"]),"_toArray",[]),"_isEmpty",[]);
  593. if(smalltalk.assert($1)){
  594. smalltalk.send((smalltalk.KeyedPubSubUnsubscribe || KeyedPubSubUnsubscribe),"_signal",[]);
  595. };
  596. return smalltalk.send(actual,"_trapDescend_",[(function(){
  597. return smalltalk.send(self,"_with_",[(function(html){
  598. return smalltalk.send(aBlock,"_value_value_",[data,html]);
  599. })]);
  600. })]);
  601. })]);
  602. })]);
  603. return self},
  604. args: ["path", "aBlock"],
  605. source: "trap: path read: aBlock\x0a\x09path trapDescend: [ | actual model |\x0a \x09actual := Trapped path.\x0a model := Trapped current byName: actual first.\x0a model watch: actual allButFirst do: [ :data |\x0a (self asJQuery closest: 'html') toArray isEmpty ifTrue: [ KeyedPubSubUnsubscribe signal ].\x0a \x09actual trapDescend: [ self with: [ :html | aBlock value: data value: html ] ]\x0a \x09]\x0a ]",
  606. messageSends: ["trapDescend:", "path", "byName:", "first", "current", "watch:do:", "allButFirst", "ifTrue:", "signal", "isEmpty", "toArray", "closest:", "asJQuery", "with:", "value:value:"],
  607. referencedClasses: ["Trapped", "KeyedPubSubUnsubscribe"]
  608. }),
  609. smalltalk.TagBrush);
  610. smalltalk.addMethod(
  611. "_trap_toggle_",
  612. smalltalk.method({
  613. selector: "trap:toggle:",
  614. category: '*Trapped-Frontend',
  615. fn: function (path,aBlock){
  616. var self=this;
  617. smalltalk.send(self,"_trap_toggle_ifNotPresent_",[path,aBlock,(function(){
  618. return smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_hide",[]);
  619. })]);
  620. return self},
  621. args: ["path", "aBlock"],
  622. source: "trap: path toggle: aBlock\x0a self trap: path toggle: aBlock ifNotPresent: [ self asJQuery hide ]",
  623. messageSends: ["trap:toggle:ifNotPresent:", "hide", "asJQuery"],
  624. referencedClasses: []
  625. }),
  626. smalltalk.TagBrush);
  627. smalltalk.addMethod(
  628. "_trap_toggle_ifNotPresent_",
  629. smalltalk.method({
  630. selector: "trap:toggle:ifNotPresent:",
  631. category: '*Trapped-Frontend',
  632. fn: function (path,aBlock,anotherBlock){
  633. var self=this;
  634. var $1,$2,$3,$4;
  635. var shown;
  636. shown=nil;
  637. smalltalk.send(self,"_trap_read_",[path,(function(data,html){
  638. $1=smalltalk.send(shown,"__eq",[smalltalk.send(data,"_notNil",[])]);
  639. if(! smalltalk.assert($1)){
  640. shown=smalltalk.send(data,"_notNil",[]);
  641. shown;
  642. $2=smalltalk.send(self,"_asJQuery",[]);
  643. smalltalk.send($2,"_empty",[]);
  644. $3=smalltalk.send($2,"_show",[]);
  645. $3;
  646. if(smalltalk.assert(shown)){
  647. $4=aBlock;
  648. } else {
  649. $4=anotherBlock;
  650. };
  651. return smalltalk.send($4,"_value_value_",[data,html]);
  652. };
  653. })]);
  654. return self},
  655. args: ["path", "aBlock", "anotherBlock"],
  656. 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 ]",
  657. messageSends: ["trap:read:", "ifFalse:", "notNil", "empty", "asJQuery", "show", "value:value:", "ifTrue:ifFalse:", "="],
  658. referencedClasses: []
  659. }),
  660. smalltalk.TagBrush);
  661. smalltalk.addMethod(
  662. "_trapIter_tag_do_",
  663. smalltalk.method({
  664. selector: "trapIter:tag:do:",
  665. category: '*Trapped-Frontend',
  666. fn: function (path,aSymbol,aBlock){
  667. var self=this;
  668. smalltalk.send(self,"_trap_read_",[path,(function(model,html){
  669. smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
  670. if(($receiver = model) == nil || $receiver == undefined){
  671. return model;
  672. } else {
  673. return smalltalk.send(model,"_withIndexDo_",[(function(item,i){
  674. return smalltalk.send(smalltalk.send(html,"_perform_",[aSymbol]),"_trap_read_",[[i],aBlock]);
  675. })]);
  676. };
  677. })]);
  678. return self},
  679. args: ["path", "aSymbol", "aBlock"],
  680. 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 ]",
  681. messageSends: ["trap:read:", "empty", "root", "ifNotNil:", "withIndexDo:", "perform:"],
  682. referencedClasses: []
  683. }),
  684. smalltalk.TagBrush);
  685. smalltalk.addMethod(
  686. "_trapShow_",
  687. smalltalk.method({
  688. selector: "trapShow:",
  689. category: '*Trapped-Frontend',
  690. fn: function (path){
  691. var self=this;
  692. smalltalk.send(self,"_trapShow_default_",[path,(function(){
  693. })]);
  694. return self},
  695. args: ["path"],
  696. source: "trapShow: path\x0a\x09self trapShow: path default: []",
  697. messageSends: ["trapShow:default:"],
  698. referencedClasses: []
  699. }),
  700. smalltalk.TagBrush);
  701. smalltalk.addMethod(
  702. "_trapShow_default_",
  703. smalltalk.method({
  704. selector: "trapShow:default:",
  705. category: '*Trapped-Frontend',
  706. fn: function (path,anObject){
  707. var self=this;
  708. var $2,$1;
  709. smalltalk.send(self,"_trap_read_",[path,(function(model){
  710. smalltalk.send(self,"_empty",[]);
  711. if(($receiver = model) == nil || $receiver == undefined){
  712. $2=anObject;
  713. } else {
  714. $2=model;
  715. };
  716. $1=smalltalk.send(self,"_with_",[$2]);
  717. return $1;
  718. })]);
  719. return self},
  720. args: ["path", "anObject"],
  721. source: "trapShow: path default: anObject\x0a\x09self trap: path read: [ :model | self empty; with: (model ifNil: [anObject]) ]",
  722. messageSends: ["trap:read:", "empty", "with:", "ifNil:"],
  723. referencedClasses: []
  724. }),
  725. smalltalk.TagBrush);