Trapped-Demo.js 14 KB

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