Trapped-Demo.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. define("gh_herby_trapped/Trapped-Demo", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "gh_herby_trapped/Trapped-Backend", "amber_core/Kernel-Objects", "amber_core/Canvas"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Trapped-Demo');
  3. smalltalk.packages["Trapped-Demo"].transport = {"type":"amd","amdNamespace":"gh_herby_trapped"};
  4. smalltalk.addClass('App', smalltalk.ListKeyedIsolatedEntity, [], 'Trapped-Demo');
  5. smalltalk.App.comment="// Code from AngularJS Todo example, http://angularjs.org/#todo-js\x0afunction TodoCtrl($scope) {\x0a $scope.todos = [\x0a {text:'learn angular', done:true},\x0a {text:'build an angular app', done:false}];\x0a \x0a $scope.addTodo = function() {\x0a $scope.todos.push({text:$scope.todoText, done:false});\x0a $scope.todoText = '';\x0a };\x0a \x0a $scope.remaining = function() {\x0a var count = 0;\x0a angular.forEach($scope.todos, function(todo) {\x0a count += todo.done ? 0 : 1;\x0a });\x0a return count;\x0a };\x0a \x0a $scope.archive = function() {\x0a var oldTodos = $scope.todos;\x0a $scope.todos = [];\x0a angular.forEach(oldTodos, function(todo) {\x0a if (!todo.done) $scope.todos.push(todo);\x0a });\x0a };\x0a}";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "initialize",
  9. category: 'initialization',
  10. fn: function (){
  11. var self=this;
  12. function $SimpleKeyedPubSub(){return smalltalk.SimpleKeyedPubSub||(typeof SimpleKeyedPubSub=="undefined"?nil:SimpleKeyedPubSub)}
  13. function $AppModel(){return smalltalk.AppModel||(typeof AppModel=="undefined"?nil:AppModel)}
  14. return smalltalk.withContext(function($ctx1) {
  15. var $1,$3,$4,$2,$6,$5;
  16. smalltalk.App.superclass.fn.prototype._initialize.apply(_st(self), []);
  17. $1=_st($SimpleKeyedPubSub())._new();
  18. $ctx1.sendIdx["new"]=1;
  19. self._dispatcher_($1);
  20. self._model_(_st(_st($AppModel())._new())._title_("Todo"));
  21. self._watch_do_([["todos"], nil],(function(){
  22. return smalltalk.withContext(function($ctx2) {
  23. return _st(self._dispatcher())._changed_([["remaining"]]);
  24. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  25. _st((function(){
  26. return smalltalk.withContext(function($ctx2) {
  27. return self._modify_do_([["todos"]],(function(){
  28. return smalltalk.withContext(function($ctx3) {
  29. $3="text".__minus_gt("learn trapped");
  30. $ctx3.sendIdx["->"]=1;
  31. $4="done".__minus_gt(true);
  32. $ctx3.sendIdx["->"]=2;
  33. $2=smalltalk.HashedCollection._from_([$3,$4]);
  34. $6="text".__minus_gt("build a trapped app");
  35. $ctx3.sendIdx["->"]=3;
  36. $5=smalltalk.HashedCollection._from_([$6,"done".__minus_gt(false)]);
  37. return [$2,$5];
  38. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)})}));
  39. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}))._valueWithTimeout_((2000));
  40. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.App)})},
  41. args: [],
  42. source: "initialize\x0a\x09super initialize.\x0a self dispatcher: SimpleKeyedPubSub new.\x0a self model: (AppModel new title: 'Todo').\x0a\x09self watch: #((todos) nil) do: [ self dispatcher changed: #((remaining)) ].\x0a [ self modify: #((todos)) do: [{\x0a #{'text'->'learn trapped'. 'done'->true}.\x0a #{'text'->'build a trapped app'. 'done'->false}\x0a }]] valueWithTimeout: 2000",
  43. messageSends: ["initialize", "dispatcher:", "new", "model:", "title:", "watch:do:", "changed:", "dispatcher", "valueWithTimeout:", "modify:do:", "->"],
  44. referencedClasses: ["SimpleKeyedPubSub", "AppModel"]
  45. }),
  46. smalltalk.App);
  47. smalltalk.addClass('AppModel', smalltalk.Object, ['title', 'todos', 'todoText'], 'Trapped-Demo');
  48. smalltalk.AppModel.comment="// Code from AngularJS Todo example, http://angularjs.org/#todo-js\x0afunction TodoCtrl($scope) {\x0a $scope.todos = [\x0a {text:'learn angular', done:true},\x0a {text:'build an angular app', done:false}];\x0a \x0a $scope.addTodo = function() {\x0a $scope.todos.push({text:$scope.todoText, done:false});\x0a $scope.todoText = '';\x0a };\x0a \x0a $scope.remaining = function() {\x0a var count = 0;\x0a angular.forEach($scope.todos, function(todo) {\x0a count += todo.done ? 0 : 1;\x0a });\x0a return count;\x0a };\x0a \x0a $scope.archive = function() {\x0a var oldTodos = $scope.todos;\x0a $scope.todos = [];\x0a angular.forEach(oldTodos, function(todo) {\x0a if (!todo.done) $scope.todos.push(todo);\x0a });\x0a };\x0a}";
  49. smalltalk.addMethod(
  50. smalltalk.method({
  51. selector: "addTodo",
  52. category: 'action',
  53. fn: function (){
  54. var self=this;
  55. return smalltalk.withContext(function($ctx1) {
  56. var $1,$3,$2;
  57. $1=self._todos();
  58. $3="text".__minus_gt(self._todoText());
  59. $ctx1.sendIdx["->"]=1;
  60. $2=smalltalk.HashedCollection._from_([$3,"done".__minus_gt(false)]);
  61. _st($1)._add_($2);
  62. self._todoText_("");
  63. return self}, function($ctx1) {$ctx1.fill(self,"addTodo",{},smalltalk.AppModel)})},
  64. args: [],
  65. source: "addTodo\x0a self todos add: #{'text'->self todoText. 'done'->false}.\x0a self todoText: ''",
  66. messageSends: ["add:", "todos", "->", "todoText", "todoText:"],
  67. referencedClasses: []
  68. }),
  69. smalltalk.AppModel);
  70. smalltalk.addMethod(
  71. smalltalk.method({
  72. selector: "archive",
  73. category: 'action',
  74. fn: function (){
  75. var self=this;
  76. return smalltalk.withContext(function($ctx1) {
  77. self._todos_(self._todosNotDone());
  78. return self}, function($ctx1) {$ctx1.fill(self,"archive",{},smalltalk.AppModel)})},
  79. args: [],
  80. source: "archive\x0a self todos: self todosNotDone",
  81. messageSends: ["todos:", "todosNotDone"],
  82. referencedClasses: []
  83. }),
  84. smalltalk.AppModel);
  85. smalltalk.addMethod(
  86. smalltalk.method({
  87. selector: "remaining",
  88. category: 'accessing',
  89. fn: function (){
  90. var self=this;
  91. return smalltalk.withContext(function($ctx1) {
  92. var $1;
  93. $1=_st(self._todosNotDone())._size();
  94. return $1;
  95. }, function($ctx1) {$ctx1.fill(self,"remaining",{},smalltalk.AppModel)})},
  96. args: [],
  97. source: "remaining\x0a ^self todosNotDone size",
  98. messageSends: ["size", "todosNotDone"],
  99. referencedClasses: []
  100. }),
  101. smalltalk.AppModel);
  102. smalltalk.addMethod(
  103. smalltalk.method({
  104. selector: "title",
  105. category: 'accessing',
  106. fn: function (){
  107. var self=this;
  108. return smalltalk.withContext(function($ctx1) {
  109. var $1;
  110. $1=self["@title"];
  111. return $1;
  112. }, function($ctx1) {$ctx1.fill(self,"title",{},smalltalk.AppModel)})},
  113. args: [],
  114. source: "title\x0a\x09^title",
  115. messageSends: [],
  116. referencedClasses: []
  117. }),
  118. smalltalk.AppModel);
  119. smalltalk.addMethod(
  120. smalltalk.method({
  121. selector: "title:",
  122. category: 'accessing',
  123. fn: function (aString){
  124. var self=this;
  125. return smalltalk.withContext(function($ctx1) {
  126. self["@title"]=aString;
  127. return self}, function($ctx1) {$ctx1.fill(self,"title:",{aString:aString},smalltalk.AppModel)})},
  128. args: ["aString"],
  129. source: "title: aString\x0a\x09title := aString",
  130. messageSends: [],
  131. referencedClasses: []
  132. }),
  133. smalltalk.AppModel);
  134. smalltalk.addMethod(
  135. smalltalk.method({
  136. selector: "todoText",
  137. category: 'accessing',
  138. fn: function (){
  139. var self=this;
  140. return smalltalk.withContext(function($ctx1) {
  141. var $1;
  142. $1=self["@todoText"];
  143. return $1;
  144. }, function($ctx1) {$ctx1.fill(self,"todoText",{},smalltalk.AppModel)})},
  145. args: [],
  146. source: "todoText\x0a\x09^todoText",
  147. messageSends: [],
  148. referencedClasses: []
  149. }),
  150. smalltalk.AppModel);
  151. smalltalk.addMethod(
  152. smalltalk.method({
  153. selector: "todoText:",
  154. category: 'accessing',
  155. fn: function (aString){
  156. var self=this;
  157. return smalltalk.withContext(function($ctx1) {
  158. self["@todoText"]=aString;
  159. return self}, function($ctx1) {$ctx1.fill(self,"todoText:",{aString:aString},smalltalk.AppModel)})},
  160. args: ["aString"],
  161. source: "todoText: aString\x0a\x09todoText := aString",
  162. messageSends: [],
  163. referencedClasses: []
  164. }),
  165. smalltalk.AppModel);
  166. smalltalk.addMethod(
  167. smalltalk.method({
  168. selector: "todos",
  169. category: 'accessing',
  170. fn: function (){
  171. var self=this;
  172. return smalltalk.withContext(function($ctx1) {
  173. var $1;
  174. $1=self["@todos"];
  175. return $1;
  176. }, function($ctx1) {$ctx1.fill(self,"todos",{},smalltalk.AppModel)})},
  177. args: [],
  178. source: "todos\x0a\x09^todos",
  179. messageSends: [],
  180. referencedClasses: []
  181. }),
  182. smalltalk.AppModel);
  183. smalltalk.addMethod(
  184. smalltalk.method({
  185. selector: "todos:",
  186. category: 'accessing',
  187. fn: function (anArray){
  188. var self=this;
  189. return smalltalk.withContext(function($ctx1) {
  190. self["@todos"]=anArray;
  191. return self}, function($ctx1) {$ctx1.fill(self,"todos:",{anArray:anArray},smalltalk.AppModel)})},
  192. args: ["anArray"],
  193. source: "todos: anArray\x0a\x09todos := anArray",
  194. messageSends: [],
  195. referencedClasses: []
  196. }),
  197. smalltalk.AppModel);
  198. smalltalk.addMethod(
  199. smalltalk.method({
  200. selector: "todosNotDone",
  201. category: 'accessing',
  202. fn: function (){
  203. var self=this;
  204. return smalltalk.withContext(function($ctx1) {
  205. var $1;
  206. $1=_st(self._todos())._reject_((function(each){
  207. return smalltalk.withContext(function($ctx2) {
  208. return _st(each)._at_("done");
  209. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  210. return $1;
  211. }, function($ctx1) {$ctx1.fill(self,"todosNotDone",{},smalltalk.AppModel)})},
  212. args: [],
  213. source: "todosNotDone\x0a ^self todos reject: [ :each | each at: 'done' ]",
  214. messageSends: ["reject:", "todos", "at:"],
  215. referencedClasses: []
  216. }),
  217. smalltalk.AppModel);
  218. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  219. smalltalk.AppView.comment="<!-- Code from AngularJS Todo example, http://angularjs.org/#todo-html -->\x0a <body>\x0a <h2>Todo</h2>\x0a <div ng-controller=\x22TodoCtrl\x22>\x0a <span>{{remaining()}} of {{todos.length}} remaining</span>\x0a [ <a href=\x22\x22 ng-click=\x22archive()\x22>archive</a> ]\x0a <ul class=\x22unstyled\x22>\x0a <li ng-repeat=\x22todo in todos\x22>\x0a <input type=\x22checkbox\x22 ng-model=\x22todo.done\x22>\x0a <span class=\x22done-{{todo.done}}\x22>{{todo.text}}</span>\x0a </li>\x0a </ul>\x0a <form ng-submit=\x22addTodo()\x22>\x0a <input type=\x22text\x22 ng-model=\x22todoText\x22 size=\x2230\x22\x0a placeholder=\x22add new todo here\x22>\x0a <input class=\x22btn-primary\x22 type=\x22submit\x22 value=\x22add\x22>\x0a </form>\x0a </div>\x0a </body>";
  220. smalltalk.addMethod(
  221. smalltalk.method({
  222. selector: "renderOn:",
  223. category: 'rendering',
  224. fn: function (html){
  225. var self=this;
  226. return smalltalk.withContext(function($ctx1) {
  227. var $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$12,$13,$14,$15,$11;
  228. []._trapDescend_((function(snap){
  229. return smalltalk.withContext(function($ctx2) {
  230. _st(_st(html)._h2())._trap_([["title"]]);
  231. $ctx2.sendIdx["trap:"]=1;
  232. _st(_st(html)._div())._trapGuard_contents_([["todos"], ["notNil"]],(function(){
  233. return smalltalk.withContext(function($ctx3) {
  234. $1=_st(html)._span();
  235. $ctx3.sendIdx["span"]=1;
  236. _st($1)._trap_([["remaining"]]);
  237. $ctx3.sendIdx["trap:"]=2;
  238. _st(html)._with_(" of ");
  239. $ctx3.sendIdx["with:"]=1;
  240. $2=_st(html)._span();
  241. $ctx3.sendIdx["span"]=2;
  242. _st($2)._trap_([["todos"], ["size"]]);
  243. $ctx3.sendIdx["trap:"]=3;
  244. _st(html)._with_(" remaining [ ");
  245. $ctx3.sendIdx["with:"]=2;
  246. $3=_st(html)._a();
  247. _st($3)._href_("");
  248. _st($3)._onClick_((function(){
  249. return smalltalk.withContext(function($ctx4) {
  250. _st(snap)._modify_((function(model){
  251. return smalltalk.withContext(function($ctx5) {
  252. return _st(model)._archive();
  253. }, function($ctx5) {$ctx5.fillBlock({model:model},$ctx4,4)})}));
  254. $ctx4.sendIdx["modify:"]=1;
  255. return false;
  256. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,3)})}));
  257. $4=_st($3)._with_("archive");
  258. $ctx3.sendIdx["with:"]=3;
  259. $4;
  260. _st(html)._with_(" ]");
  261. $ctx3.sendIdx["with:"]=4;
  262. _st(_st(html)._ul())._with_((function(){
  263. return smalltalk.withContext(function($ctx4) {
  264. return _st(html)._trapIter_tag_do_([["todos"]],"li",(function(each){
  265. return smalltalk.withContext(function($ctx5) {
  266. $5=_st(html)._root();
  267. $ctx5.sendIdx["root"]=1;
  268. _st($5)._empty();
  269. $6=_st(html)._input();
  270. $ctx5.sendIdx["input"]=1;
  271. _st($6)._type_("checkbox");
  272. $ctx5.sendIdx["type:"]=1;
  273. $7=_st($6)._trap_(["done"]);
  274. $ctx5.sendIdx["trap:"]=4;
  275. $7;
  276. $8=_st(html)._span();
  277. _st($8)._trap_read_(["done"],(function(model){
  278. return smalltalk.withContext(function($ctx6) {
  279. return _st(_st(html)._root())._class_("done-".__comma(model));
  280. $ctx6.sendIdx["class:"]=1;
  281. }, function($ctx6) {$ctx6.fillBlock({model:model},$ctx5,7)})}));
  282. $9=_st($8)._trap_(["text"]);
  283. $ctx5.sendIdx["trap:"]=5;
  284. return $9;
  285. }, function($ctx5) {$ctx5.fillBlock({each:each},$ctx4,6)})}));
  286. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,5)})}));
  287. $ctx3.sendIdx["with:"]=5;
  288. $10=_st(html)._form();
  289. _st($10)._onSubmit_((function(){
  290. return smalltalk.withContext(function($ctx4) {
  291. _st(snap)._modify_((function(model){
  292. return smalltalk.withContext(function($ctx5) {
  293. return _st(model)._addTodo();
  294. }, function($ctx5) {$ctx5.fillBlock({model:model},$ctx4,9)})}));
  295. return false;
  296. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,8)})}));
  297. $11=_st($10)._with_((function(){
  298. return smalltalk.withContext(function($ctx4) {
  299. $12=_st(html)._input();
  300. $ctx4.sendIdx["input"]=2;
  301. _st($12)._type_("text");
  302. $ctx4.sendIdx["type:"]=2;
  303. _st($12)._trap_([["todoText"]]);
  304. _st($12)._at_put_("size",(30));
  305. $13=_st($12)._placeholder_("add new todo here");
  306. $13;
  307. $14=_st(html)._input();
  308. _st($14)._class_("btn-primary");
  309. _st($14)._type_("submit");
  310. $15=_st($14)._value_("add");
  311. return $15;
  312. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,10)})}));
  313. return $11;
  314. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  315. $ctx2.sendIdx["trapGuard:contents:"]=1;
  316. return _st(_st(html)._p())._trapGuard_contents_([["todos"], ["isNil"]],"Loading ...");
  317. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1,1)})}));
  318. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.AppView)})},
  319. args: ["html"],
  320. source: "renderOn: html\x0a #() trapDescend: [ :snap |\x0a\x09html h2 trap: #((title)).\x0a html div trapGuard: #((todos) (notNil)) contents: [\x0a html span trap:#((remaining)).\x0a html with: ' of '.\x0a html span trap: #((todos) (size)).\x0a html with: ' remaining [ '.\x0a html a href:''; onClick: [\x0a snap modify: [ :model | model archive ].\x0a false\x0a ]; with: 'archive'.\x0a html with: ' ]'.\x0a html ul with: [ html trapIter: #((todos)) tag: #li do: [ :each |\x0a html root empty.\x0a html input type: 'checkbox'; trap: #('done').\x0a html span trap: #('done') read: [ :model | html root class: 'done-', model ]; trap: #('text').\x0a ]].\x0a html form onSubmit: [\x0a snap modify: [ :model | model addTodo ].\x0a false\x0a ]; with: [\x0a html input type: 'text'; trap: #((todoText)); at: 'size' put: 30; placeholder: 'add new todo here'.\x0a html input class: 'btn-primary'; type: 'submit'; value: 'add'.\x0a ].\x0a ].\x0a\x09html p trapGuard: #((todos) (isNil)) contents: 'Loading ...'.\x0a\x09]",
  321. messageSends: ["trapDescend:", "trap:", "h2", "trapGuard:contents:", "div", "span", "with:", "href:", "a", "onClick:", "modify:", "archive", "ul", "trapIter:tag:do:", "empty", "root", "type:", "input", "trap:read:", "class:", ",", "onSubmit:", "form", "addTodo", "at:put:", "placeholder:", "value:", "p"],
  322. referencedClasses: []
  323. }),
  324. smalltalk.AppView);
  325. });