Trapped-Demo.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. smalltalk.send(self,"_initialize",[],smalltalk.ListKeyedIsolatedEntity);
  12. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.SimpleKeyedPubSub || SimpleKeyedPubSub),"_new",[])]);
  13. smalltalk.send(self,"_model_",[smalltalk.send(smalltalk.send((smalltalk.AppModel || AppModel),"_new",[]),"_title_",["Todo"])]);
  14. smalltalk.send((function(){
  15. return smalltalk.send(self,"_modify_do_",[[smalltalk.symbolFor("todos")],(function(){
  16. return [smalltalk.HashedCollection._fromPairs_([smalltalk.send("text","__minus_gt",["learn trapped"]),smalltalk.send("done","__minus_gt",[true])]),smalltalk.HashedCollection._fromPairs_([smalltalk.send("text","__minus_gt",["build a trapped app"]),smalltalk.send("done","__minus_gt",[false])])];
  17. })]);
  18. }),"_valueWithTimeout_",[(2000)]);
  19. return self},
  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. smalltalk.send(smalltalk.send(self,"_todos",[]),"_add_",[smalltalk.HashedCollection._fromPairs_([smalltalk.send("text","__minus_gt",[smalltalk.send(self,"_todoText",[])]),smalltalk.send("done","__minus_gt",[false])])]);
  36. smalltalk.send(self,"_todoText_",[""]);
  37. return self},
  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. smalltalk.send(self,"_todos_",[smalltalk.send(self,"_todosNotDone",[])]);
  52. return self},
  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. var $1;
  67. $1=smalltalk.send(smalltalk.send(self,"_todosNotDone",[]),"_size",[]);
  68. return $1;
  69. },
  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 self["@title"];
  84. },
  85. args: [],
  86. source: "title\x0a\x09^title",
  87. messageSends: [],
  88. referencedClasses: []
  89. }),
  90. smalltalk.AppModel);
  91. smalltalk.addMethod(
  92. "_title_",
  93. smalltalk.method({
  94. selector: "title:",
  95. category: 'accessing',
  96. fn: function (aString){
  97. var self=this;
  98. self["@title"]=aString;
  99. return self},
  100. args: ["aString"],
  101. source: "title: aString\x0a\x09title := aString",
  102. messageSends: [],
  103. referencedClasses: []
  104. }),
  105. smalltalk.AppModel);
  106. smalltalk.addMethod(
  107. "_todoText",
  108. smalltalk.method({
  109. selector: "todoText",
  110. category: 'accessing',
  111. fn: function (){
  112. var self=this;
  113. return self["@todoText"];
  114. },
  115. args: [],
  116. source: "todoText\x0a\x09^todoText",
  117. messageSends: [],
  118. referencedClasses: []
  119. }),
  120. smalltalk.AppModel);
  121. smalltalk.addMethod(
  122. "_todoText_",
  123. smalltalk.method({
  124. selector: "todoText:",
  125. category: 'accessing',
  126. fn: function (aString){
  127. var self=this;
  128. self["@todoText"]=aString;
  129. return self},
  130. args: ["aString"],
  131. source: "todoText: aString\x0a\x09todoText := aString",
  132. messageSends: [],
  133. referencedClasses: []
  134. }),
  135. smalltalk.AppModel);
  136. smalltalk.addMethod(
  137. "_todos",
  138. smalltalk.method({
  139. selector: "todos",
  140. category: 'accessing',
  141. fn: function (){
  142. var self=this;
  143. return self["@todos"];
  144. },
  145. args: [],
  146. source: "todos\x0a\x09^todos",
  147. messageSends: [],
  148. referencedClasses: []
  149. }),
  150. smalltalk.AppModel);
  151. smalltalk.addMethod(
  152. "_todos_",
  153. smalltalk.method({
  154. selector: "todos:",
  155. category: 'accessing',
  156. fn: function (anArray){
  157. var self=this;
  158. self["@todos"]=anArray;
  159. return self},
  160. args: ["anArray"],
  161. source: "todos: anArray\x0a\x09todos := anArray",
  162. messageSends: [],
  163. referencedClasses: []
  164. }),
  165. smalltalk.AppModel);
  166. smalltalk.addMethod(
  167. "_todosNotDone",
  168. smalltalk.method({
  169. selector: "todosNotDone",
  170. category: 'accessing',
  171. fn: function (){
  172. var self=this;
  173. var $1;
  174. $1=smalltalk.send(smalltalk.send(self,"_todos",[]),"_reject_",[(function(each){
  175. return smalltalk.send(each,"_at_",["done"]);
  176. })]);
  177. return $1;
  178. },
  179. args: [],
  180. source: "todosNotDone\x0a ^self todos reject: [ :each | each at: 'done' ]",
  181. messageSends: ["reject:", "at:", "todos"],
  182. referencedClasses: []
  183. }),
  184. smalltalk.AppModel);
  185. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  186. 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"
  187. smalltalk.addMethod(
  188. "_renderOn_",
  189. smalltalk.method({
  190. selector: "renderOn:",
  191. category: 'rendering',
  192. fn: function (html){
  193. var self=this;
  194. var $1,$2,$3,$4,$5,$6,$7,$9,$10,$11,$12,$8;
  195. smalltalk.send([],"_trapDescend_",[(function(snap){
  196. smalltalk.send(smalltalk.send(html,"_h2",[]),"_trap_",[[smalltalk.symbolFor("title")]]);
  197. return smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[[smalltalk.symbolFor("todos")],(function(){
  198. return smalltalk.send(snap,"_do_",[(function(){
  199. smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[smalltalk.symbolFor("remaining")]]);
  200. smalltalk.send(html,"_with_",[" of "]);
  201. smalltalk.send(smalltalk.send(html,"_span",[]),"_trap_",[[smalltalk.symbolFor("todos"), smalltalk.symbolFor("size")]]);
  202. smalltalk.send(html,"_with_",[" remaining [ "]);
  203. $1=smalltalk.send(html,"_a",[]);
  204. smalltalk.send($1,"_href_",[""]);
  205. smalltalk.send($1,"_onClick_",[(function(){
  206. return smalltalk.send((function(){
  207. smalltalk.send(snap,"_modify_",[(function(model){
  208. return smalltalk.send(model,"_archive",[]);
  209. })]);
  210. return false;
  211. }),"_value",[]);
  212. })]);
  213. $2=smalltalk.send($1,"_with_",["archive"]);
  214. $2;
  215. smalltalk.send(html,"_with_",[" ]"]);
  216. smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[smalltalk.symbolFor("todos")],smalltalk.symbolFor("li"),(function(each){
  217. smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
  218. $3=smalltalk.send(html,"_input",[]);
  219. smalltalk.send($3,"_type_",["checkbox"]);
  220. $4=smalltalk.send($3,"_trap_",[["done"]]);
  221. $4;
  222. $5=smalltalk.send(html,"_span",[]);
  223. smalltalk.send($5,"_trap_read_",[["done"],(function(model){
  224. return smalltalk.send(smalltalk.send(html,"_root",[]),"_class_",[smalltalk.send("done-","__comma",[model])]);
  225. })]);
  226. $6=smalltalk.send($5,"_trap_",[["text"]]);
  227. return $6;
  228. })]);
  229. $7=smalltalk.send(html,"_form",[]);
  230. smalltalk.send($7,"_onSubmit_",[(function(){
  231. return smalltalk.send((function(){
  232. smalltalk.send(snap,"_modify_",[(function(model){
  233. return smalltalk.send(model,"_addTodo",[]);
  234. })]);
  235. return false;
  236. }),"_value",[]);
  237. })]);
  238. $8=smalltalk.send($7,"_with_",[(function(){
  239. $9=smalltalk.send(html,"_input",[]);
  240. smalltalk.send($9,"_type_",["text"]);
  241. smalltalk.send($9,"_trap_",[[smalltalk.symbolFor("todoText")]]);
  242. smalltalk.send($9,"_at_put_",["size",(30)]);
  243. $10=smalltalk.send($9,"_placeholder_",["add new todo here"]);
  244. $10;
  245. $11=smalltalk.send(html,"_input",[]);
  246. smalltalk.send($11,"_class_",["btn-primary"]);
  247. smalltalk.send($11,"_type_",["submit"]);
  248. $12=smalltalk.send($11,"_value_",["add"]);
  249. return $12;
  250. })]);
  251. return $8;
  252. })]);
  253. }),(function(){
  254. return smalltalk.send(html,"_with_",["Loading ..."]);
  255. })]);
  256. })]);
  257. return self},
  258. args: ["html"],
  259. 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 ] value \x22amber GH-314 workaround\x22]; with: 'archive'.\x0a html with: ' ]'.\x0a html ul 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 ] value \x22amber GH-314 workaround\x22]; 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 ...' ]]",
  260. messageSends: ["trapDescend:", "trap:", "h2", "trap:toggle:ifNotPresent:", "do:", "span", "with:", "href:", "a", "onClick:", "value", "modify:", "archive", "trapIter:tag:do:", "empty", "root", "type:", "input", "trap:read:", "class:", ",", "ul", "onSubmit:", "addTodo", "form", "at:put:", "placeholder:", "value:", "div"],
  261. referencedClasses: []
  262. }),
  263. smalltalk.AppView);