Trapped-Demo.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. smalltalk.App.superclass.fn.prototype._initialize.apply(_st(self), []);
  16. self._dispatcher_(_st($SimpleKeyedPubSub())._new());
  17. self._model_(_st(_st($AppModel())._new())._title_("Todo"));
  18. self._watch_do_([["todos"], nil],(function(){
  19. return smalltalk.withContext(function($ctx2) {
  20. return _st(self._dispatcher())._changed_([["remaining"]]);
  21. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  22. _st((function(){
  23. return smalltalk.withContext(function($ctx2) {
  24. return self._modify_do_([["todos"]],(function(){
  25. return smalltalk.withContext(function($ctx3) {
  26. return [smalltalk.HashedCollection._from_(["text".__minus_gt("learn trapped"),"done".__minus_gt(true)]),smalltalk.HashedCollection._from_(["text".__minus_gt("build a trapped app"),"done".__minus_gt(false)])];
  27. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
  28. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._valueWithTimeout_((2000));
  29. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.App)})},
  30. args: [],
  31. 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",
  32. messageSends: ["initialize", "dispatcher:", "new", "model:", "title:", "watch:do:", "changed:", "dispatcher", "valueWithTimeout:", "modify:do:", "->"],
  33. referencedClasses: ["SimpleKeyedPubSub", "AppModel"]
  34. }),
  35. smalltalk.App);
  36. smalltalk.addClass('AppModel', smalltalk.Object, ['title', 'todos', 'todoText'], 'Trapped-Demo');
  37. 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}";
  38. smalltalk.addMethod(
  39. smalltalk.method({
  40. selector: "addTodo",
  41. category: 'action',
  42. fn: function (){
  43. var self=this;
  44. return smalltalk.withContext(function($ctx1) {
  45. _st(self._todos())._add_(smalltalk.HashedCollection._from_(["text".__minus_gt(self._todoText()),"done".__minus_gt(false)]));
  46. self._todoText_("");
  47. return self}, function($ctx1) {$ctx1.fill(self,"addTodo",{},smalltalk.AppModel)})},
  48. args: [],
  49. source: "addTodo\x0a self todos add: #{'text'->self todoText. 'done'->false}.\x0a self todoText: ''",
  50. messageSends: ["add:", "->", "todoText", "todos", "todoText:"],
  51. referencedClasses: []
  52. }),
  53. smalltalk.AppModel);
  54. smalltalk.addMethod(
  55. smalltalk.method({
  56. selector: "archive",
  57. category: 'action',
  58. fn: function (){
  59. var self=this;
  60. return smalltalk.withContext(function($ctx1) {
  61. self._todos_(self._todosNotDone());
  62. return self}, function($ctx1) {$ctx1.fill(self,"archive",{},smalltalk.AppModel)})},
  63. args: [],
  64. source: "archive\x0a self todos: self todosNotDone",
  65. messageSends: ["todos:", "todosNotDone"],
  66. referencedClasses: []
  67. }),
  68. smalltalk.AppModel);
  69. smalltalk.addMethod(
  70. smalltalk.method({
  71. selector: "remaining",
  72. category: 'accessing',
  73. fn: function (){
  74. var self=this;
  75. return smalltalk.withContext(function($ctx1) {
  76. var $1;
  77. $1=_st(self._todosNotDone())._size();
  78. return $1;
  79. }, function($ctx1) {$ctx1.fill(self,"remaining",{},smalltalk.AppModel)})},
  80. args: [],
  81. source: "remaining\x0a ^self todosNotDone size",
  82. messageSends: ["size", "todosNotDone"],
  83. referencedClasses: []
  84. }),
  85. smalltalk.AppModel);
  86. smalltalk.addMethod(
  87. smalltalk.method({
  88. selector: "title",
  89. category: 'accessing',
  90. fn: function (){
  91. var self=this;
  92. return smalltalk.withContext(function($ctx1) {
  93. var $1;
  94. $1=self["@title"];
  95. return $1;
  96. }, function($ctx1) {$ctx1.fill(self,"title",{},smalltalk.AppModel)})},
  97. args: [],
  98. source: "title\x0a\x09^title",
  99. messageSends: [],
  100. referencedClasses: []
  101. }),
  102. smalltalk.AppModel);
  103. smalltalk.addMethod(
  104. smalltalk.method({
  105. selector: "title:",
  106. category: 'accessing',
  107. fn: function (aString){
  108. var self=this;
  109. return smalltalk.withContext(function($ctx1) {
  110. self["@title"]=aString;
  111. return self}, function($ctx1) {$ctx1.fill(self,"title:",{aString:aString},smalltalk.AppModel)})},
  112. args: ["aString"],
  113. source: "title: aString\x0a\x09title := aString",
  114. messageSends: [],
  115. referencedClasses: []
  116. }),
  117. smalltalk.AppModel);
  118. smalltalk.addMethod(
  119. smalltalk.method({
  120. selector: "todoText",
  121. category: 'accessing',
  122. fn: function (){
  123. var self=this;
  124. return smalltalk.withContext(function($ctx1) {
  125. var $1;
  126. $1=self["@todoText"];
  127. return $1;
  128. }, function($ctx1) {$ctx1.fill(self,"todoText",{},smalltalk.AppModel)})},
  129. args: [],
  130. source: "todoText\x0a\x09^todoText",
  131. messageSends: [],
  132. referencedClasses: []
  133. }),
  134. smalltalk.AppModel);
  135. smalltalk.addMethod(
  136. smalltalk.method({
  137. selector: "todoText:",
  138. category: 'accessing',
  139. fn: function (aString){
  140. var self=this;
  141. return smalltalk.withContext(function($ctx1) {
  142. self["@todoText"]=aString;
  143. return self}, function($ctx1) {$ctx1.fill(self,"todoText:",{aString:aString},smalltalk.AppModel)})},
  144. args: ["aString"],
  145. source: "todoText: aString\x0a\x09todoText := aString",
  146. messageSends: [],
  147. referencedClasses: []
  148. }),
  149. smalltalk.AppModel);
  150. smalltalk.addMethod(
  151. smalltalk.method({
  152. selector: "todos",
  153. category: 'accessing',
  154. fn: function (){
  155. var self=this;
  156. return smalltalk.withContext(function($ctx1) {
  157. var $1;
  158. $1=self["@todos"];
  159. return $1;
  160. }, function($ctx1) {$ctx1.fill(self,"todos",{},smalltalk.AppModel)})},
  161. args: [],
  162. source: "todos\x0a\x09^todos",
  163. messageSends: [],
  164. referencedClasses: []
  165. }),
  166. smalltalk.AppModel);
  167. smalltalk.addMethod(
  168. smalltalk.method({
  169. selector: "todos:",
  170. category: 'accessing',
  171. fn: function (anArray){
  172. var self=this;
  173. return smalltalk.withContext(function($ctx1) {
  174. self["@todos"]=anArray;
  175. return self}, function($ctx1) {$ctx1.fill(self,"todos:",{anArray:anArray},smalltalk.AppModel)})},
  176. args: ["anArray"],
  177. source: "todos: anArray\x0a\x09todos := anArray",
  178. messageSends: [],
  179. referencedClasses: []
  180. }),
  181. smalltalk.AppModel);
  182. smalltalk.addMethod(
  183. smalltalk.method({
  184. selector: "todosNotDone",
  185. category: 'accessing',
  186. fn: function (){
  187. var self=this;
  188. return smalltalk.withContext(function($ctx1) {
  189. var $1;
  190. $1=_st(self._todos())._reject_((function(each){
  191. return smalltalk.withContext(function($ctx2) {
  192. return _st(each)._at_("done");
  193. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  194. return $1;
  195. }, function($ctx1) {$ctx1.fill(self,"todosNotDone",{},smalltalk.AppModel)})},
  196. args: [],
  197. source: "todosNotDone\x0a ^self todos reject: [ :each | each at: 'done' ]",
  198. messageSends: ["reject:", "at:", "todos"],
  199. referencedClasses: []
  200. }),
  201. smalltalk.AppModel);
  202. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  203. 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>";
  204. smalltalk.addMethod(
  205. smalltalk.method({
  206. selector: "renderOn:",
  207. category: 'rendering',
  208. fn: function (html){
  209. var self=this;
  210. return smalltalk.withContext(function($ctx1) {
  211. var $1,$2,$3,$4,$5,$6,$7,$9,$10,$11,$12,$8;
  212. []._trapDescend_((function(snap){
  213. return smalltalk.withContext(function($ctx2) {
  214. _st(_st(html)._h2())._trap_([["title"]]);
  215. return _st(_st(html)._div())._trap_toggle_ifNotPresent_([["todos"]],(function(){
  216. return smalltalk.withContext(function($ctx3) {
  217. return _st(snap)._do_((function(){
  218. return smalltalk.withContext(function($ctx4) {
  219. _st(_st(html)._span())._trap_([["remaining"]]);
  220. _st(html)._with_(" of ");
  221. _st(_st(html)._span())._trap_([["todos"], ["size"]]);
  222. _st(html)._with_(" remaining [ ");
  223. $1=_st(html)._a();
  224. _st($1)._href_("");
  225. _st($1)._onClick_((function(){
  226. return smalltalk.withContext(function($ctx5) {
  227. _st(snap)._modify_((function(model){
  228. return smalltalk.withContext(function($ctx6) {
  229. return _st(model)._archive();
  230. }, function($ctx6) {$ctx6.fillBlock({model:model},$ctx5)})}));
  231. return false;
  232. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  233. $2=_st($1)._with_("archive");
  234. $2;
  235. _st(html)._with_(" ]");
  236. _st(_st(html)._ul())._with_((function(){
  237. return smalltalk.withContext(function($ctx5) {
  238. return _st(html)._trapIter_tag_do_([["todos"]],"li",(function(each){
  239. return smalltalk.withContext(function($ctx6) {
  240. _st(_st(html)._root())._empty();
  241. $3=_st(html)._input();
  242. _st($3)._type_("checkbox");
  243. $4=_st($3)._trap_(["done"]);
  244. $4;
  245. $5=_st(html)._span();
  246. _st($5)._trap_read_(["done"],(function(model){
  247. return smalltalk.withContext(function($ctx7) {
  248. return _st(_st(html)._root())._class_("done-".__comma(model));
  249. }, function($ctx7) {$ctx7.fillBlock({model:model},$ctx6)})}));
  250. $6=_st($5)._trap_(["text"]);
  251. return $6;
  252. }, function($ctx6) {$ctx6.fillBlock({each:each},$ctx5)})}));
  253. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  254. $7=_st(html)._form();
  255. _st($7)._onSubmit_((function(){
  256. return smalltalk.withContext(function($ctx5) {
  257. _st(snap)._modify_((function(model){
  258. return smalltalk.withContext(function($ctx6) {
  259. return _st(model)._addTodo();
  260. }, function($ctx6) {$ctx6.fillBlock({model:model},$ctx5)})}));
  261. return false;
  262. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  263. $8=_st($7)._with_((function(){
  264. return smalltalk.withContext(function($ctx5) {
  265. $9=_st(html)._input();
  266. _st($9)._type_("text");
  267. _st($9)._trap_([["todoText"]]);
  268. _st($9)._at_put_("size",(30));
  269. $10=_st($9)._placeholder_("add new todo here");
  270. $10;
  271. $11=_st(html)._input();
  272. _st($11)._class_("btn-primary");
  273. _st($11)._type_("submit");
  274. $12=_st($11)._value_("add");
  275. return $12;
  276. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  277. return $8;
  278. }, function($ctx4) {$ctx4.fillBlock({},$ctx3)})}));
  279. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}),(function(){
  280. return smalltalk.withContext(function($ctx3) {
  281. return _st(html)._with_("Loading ...");
  282. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
  283. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1)})}));
  284. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.AppView)})},
  285. args: ["html"],
  286. source: "renderOn: html\x0a #() trapDescend: [ :snap |\x0a\x09html h2 trap: #((title)).\x0a html div trap: #((todos)) toggle: [ snap do: [\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 ]] ifNotPresent: [ html with: 'Loading ...' ]]",
  287. messageSends: ["trapDescend:", "trap:", "h2", "trap:toggle:ifNotPresent:", "do:", "span", "with:", "href:", "a", "onClick:", "modify:", "archive", "trapIter:tag:do:", "empty", "root", "type:", "input", "trap:read:", "class:", ",", "ul", "onSubmit:", "addTodo", "form", "at:put:", "placeholder:", "value:", "div"],
  288. referencedClasses: []
  289. }),
  290. smalltalk.AppView);
  291. });