Trapped-Todo.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. define("gh_herby_trapped_todo/Trapped-Todo", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "gh_herby_trapped/Trapped-Backend", "amber_core/Kernel-Objects", "gh_herby_trapped/Trapped-Frontend"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Trapped-Todo');
  3. smalltalk.packages["Trapped-Todo"].transport = {"type":"amd","amdNamespace":"gh_herby_trapped_todo"};
  4. smalltalk.addClass('App', smalltalk.ListKeyedIsolatedEntity, [], 'Trapped-Todo');
  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-Todo');
  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.addMethod(
  219. smalltalk.method({
  220. selector: "classDoneXxx",
  221. category: '*Trapped-Todo',
  222. fn: function (){
  223. var self=this;
  224. return smalltalk.withContext(function($ctx1) {
  225. var $1;
  226. $1=self._dataToView_((function(carrier){
  227. return smalltalk.withContext(function($ctx2) {
  228. return _st(_st(carrier)._target())._class_("done-".__comma(_st(carrier)._value()));
  229. }, function($ctx2) {$ctx2.fillBlock({carrier:carrier},$ctx1,1)})}));
  230. return $1;
  231. }, function($ctx1) {$ctx1.fill(self,"classDoneXxx",{},smalltalk.TrappedProcessor.klass)})},
  232. args: [],
  233. source: "classDoneXxx\x0a\x09\x22This processor is not used any more,\x0a\x09it was replaced by generic\x0a\x09(replace ^ with ^done-) (attr class)\x0a\x09in HTML.\x0a\x0a\x09This example is left here to show how you can create quick\x0a\x09toView-only processor without class by just passing a block\x22\x0a\x0a\x09^self dataToView: [ :carrier | carrier target class: 'done-', carrier value ]",
  234. messageSends: ["dataToView:", "class:", "target", ",", "value"],
  235. referencedClasses: []
  236. }),
  237. smalltalk.TrappedProcessor.klass);
  238. });