Trapped-Demo.js 14 KB

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