Trapped-Todo.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. define("trapped-todo/Trapped-Todo", ["amber/boot", "trapped/Trapped-Backend", "amber_core/Kernel-Objects", "trapped/Trapped-Frontend"], function($boot){
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. $core.addPackage('Trapped-Todo');
  4. $core.packages["Trapped-Todo"].innerEval = function (expr) { return eval(expr); };
  5. $core.packages["Trapped-Todo"].transport = {"type":"amd","amdNamespace":"trapped-todo"};
  6. $core.addClass('App', $globals.ListKeyedIsolatedEntity, [], 'Trapped-Todo');
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.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}";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "initialize",
  13. protocol: 'initialization',
  14. fn: function (){
  15. var self=this;
  16. function $SimpleKeyedPubSub(){return $globals.SimpleKeyedPubSub||(typeof SimpleKeyedPubSub=="undefined"?nil:SimpleKeyedPubSub)}
  17. function $AppModel(){return $globals.AppModel||(typeof AppModel=="undefined"?nil:AppModel)}
  18. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  19. return $core.withContext(function($ctx1) {
  20. //>>excludeEnd("ctx");
  21. var $1;
  22. (
  23. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  24. $ctx1.supercall = true,
  25. //>>excludeEnd("ctx");
  26. $globals.App.superclass.fn.prototype._initialize.apply($recv(self), []));
  27. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  28. $ctx1.supercall = false;
  29. //>>excludeEnd("ctx");;
  30. $1=$recv($SimpleKeyedPubSub())._new();
  31. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  32. $ctx1.sendIdx["new"]=1;
  33. //>>excludeEnd("ctx");
  34. self._dispatcher_($1);
  35. self._model_($recv($recv($AppModel())._new())._title_("Todo"));
  36. self._watch_do_([["todos"], nil],(function(){
  37. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  38. return $core.withContext(function($ctx2) {
  39. //>>excludeEnd("ctx");
  40. return $recv(self._dispatcher())._changed_([["remaining"]]);
  41. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  42. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  43. //>>excludeEnd("ctx");
  44. }));
  45. $recv((function(){
  46. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  47. return $core.withContext(function($ctx2) {
  48. //>>excludeEnd("ctx");
  49. return self._modify_do_([["todos"]],(function(){
  50. return [$globals.HashedCollection._newFromPairs_(["text","learn trapped","done",true]),$globals.HashedCollection._newFromPairs_(["text","build a trapped app","done",false])];
  51. }));
  52. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  53. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  54. //>>excludeEnd("ctx");
  55. }))._valueWithTimeout_((2000));
  56. return self;
  57. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  58. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.App)});
  59. //>>excludeEnd("ctx");
  60. },
  61. //>>excludeStart("ide", pragmas.excludeIdeData);
  62. args: [],
  63. 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",
  64. referencedClasses: ["SimpleKeyedPubSub", "AppModel"],
  65. //>>excludeEnd("ide");
  66. messageSends: ["initialize", "dispatcher:", "new", "model:", "title:", "watch:do:", "changed:", "dispatcher", "valueWithTimeout:", "modify:do:"]
  67. }),
  68. $globals.App);
  69. $core.addClass('AppModel', $globals.Object, ['title', 'todos', 'todoText'], 'Trapped-Todo');
  70. //>>excludeStart("ide", pragmas.excludeIdeData);
  71. $globals.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}";
  72. //>>excludeEnd("ide");
  73. $core.addMethod(
  74. $core.method({
  75. selector: "addTodo",
  76. protocol: 'action',
  77. fn: function (){
  78. var self=this;
  79. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  80. return $core.withContext(function($ctx1) {
  81. //>>excludeEnd("ctx");
  82. $recv(self._todos())._add_($globals.HashedCollection._newFromPairs_(["text",self._todoText(),"done",false]));
  83. self._todoText_("");
  84. return self;
  85. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  86. }, function($ctx1) {$ctx1.fill(self,"addTodo",{},$globals.AppModel)});
  87. //>>excludeEnd("ctx");
  88. },
  89. //>>excludeStart("ide", pragmas.excludeIdeData);
  90. args: [],
  91. source: "addTodo\x0a self todos add: #{'text'->self todoText. 'done'->false}.\x0a self todoText: ''",
  92. referencedClasses: [],
  93. //>>excludeEnd("ide");
  94. messageSends: ["add:", "todos", "todoText", "todoText:"]
  95. }),
  96. $globals.AppModel);
  97. $core.addMethod(
  98. $core.method({
  99. selector: "archive",
  100. protocol: 'action',
  101. fn: function (){
  102. var self=this;
  103. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  104. return $core.withContext(function($ctx1) {
  105. //>>excludeEnd("ctx");
  106. self._todos_(self._todosNotDone());
  107. return self;
  108. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  109. }, function($ctx1) {$ctx1.fill(self,"archive",{},$globals.AppModel)});
  110. //>>excludeEnd("ctx");
  111. },
  112. //>>excludeStart("ide", pragmas.excludeIdeData);
  113. args: [],
  114. source: "archive\x0a self todos: self todosNotDone",
  115. referencedClasses: [],
  116. //>>excludeEnd("ide");
  117. messageSends: ["todos:", "todosNotDone"]
  118. }),
  119. $globals.AppModel);
  120. $core.addMethod(
  121. $core.method({
  122. selector: "remaining",
  123. protocol: 'accessing',
  124. fn: function (){
  125. var self=this;
  126. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  127. return $core.withContext(function($ctx1) {
  128. //>>excludeEnd("ctx");
  129. var $1;
  130. $1=$recv(self._todosNotDone())._size();
  131. return $1;
  132. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  133. }, function($ctx1) {$ctx1.fill(self,"remaining",{},$globals.AppModel)});
  134. //>>excludeEnd("ctx");
  135. },
  136. //>>excludeStart("ide", pragmas.excludeIdeData);
  137. args: [],
  138. source: "remaining\x0a ^self todosNotDone size",
  139. referencedClasses: [],
  140. //>>excludeEnd("ide");
  141. messageSends: ["size", "todosNotDone"]
  142. }),
  143. $globals.AppModel);
  144. $core.addMethod(
  145. $core.method({
  146. selector: "title",
  147. protocol: 'accessing',
  148. fn: function (){
  149. var self=this;
  150. var $1;
  151. $1=self["@title"];
  152. return $1;
  153. },
  154. //>>excludeStart("ide", pragmas.excludeIdeData);
  155. args: [],
  156. source: "title\x0a\x09^title",
  157. referencedClasses: [],
  158. //>>excludeEnd("ide");
  159. messageSends: []
  160. }),
  161. $globals.AppModel);
  162. $core.addMethod(
  163. $core.method({
  164. selector: "title:",
  165. protocol: 'accessing',
  166. fn: function (aString){
  167. var self=this;
  168. self["@title"]=aString;
  169. return self;
  170. },
  171. //>>excludeStart("ide", pragmas.excludeIdeData);
  172. args: ["aString"],
  173. source: "title: aString\x0a\x09title := aString",
  174. referencedClasses: [],
  175. //>>excludeEnd("ide");
  176. messageSends: []
  177. }),
  178. $globals.AppModel);
  179. $core.addMethod(
  180. $core.method({
  181. selector: "todoText",
  182. protocol: 'accessing',
  183. fn: function (){
  184. var self=this;
  185. var $1;
  186. $1=self["@todoText"];
  187. return $1;
  188. },
  189. //>>excludeStart("ide", pragmas.excludeIdeData);
  190. args: [],
  191. source: "todoText\x0a\x09^todoText",
  192. referencedClasses: [],
  193. //>>excludeEnd("ide");
  194. messageSends: []
  195. }),
  196. $globals.AppModel);
  197. $core.addMethod(
  198. $core.method({
  199. selector: "todoText:",
  200. protocol: 'accessing',
  201. fn: function (aString){
  202. var self=this;
  203. self["@todoText"]=aString;
  204. return self;
  205. },
  206. //>>excludeStart("ide", pragmas.excludeIdeData);
  207. args: ["aString"],
  208. source: "todoText: aString\x0a\x09todoText := aString",
  209. referencedClasses: [],
  210. //>>excludeEnd("ide");
  211. messageSends: []
  212. }),
  213. $globals.AppModel);
  214. $core.addMethod(
  215. $core.method({
  216. selector: "todos",
  217. protocol: 'accessing',
  218. fn: function (){
  219. var self=this;
  220. var $1;
  221. $1=self["@todos"];
  222. return $1;
  223. },
  224. //>>excludeStart("ide", pragmas.excludeIdeData);
  225. args: [],
  226. source: "todos\x0a\x09^todos",
  227. referencedClasses: [],
  228. //>>excludeEnd("ide");
  229. messageSends: []
  230. }),
  231. $globals.AppModel);
  232. $core.addMethod(
  233. $core.method({
  234. selector: "todos:",
  235. protocol: 'accessing',
  236. fn: function (anArray){
  237. var self=this;
  238. self["@todos"]=anArray;
  239. return self;
  240. },
  241. //>>excludeStart("ide", pragmas.excludeIdeData);
  242. args: ["anArray"],
  243. source: "todos: anArray\x0a\x09todos := anArray",
  244. referencedClasses: [],
  245. //>>excludeEnd("ide");
  246. messageSends: []
  247. }),
  248. $globals.AppModel);
  249. $core.addMethod(
  250. $core.method({
  251. selector: "todosNotDone",
  252. protocol: 'accessing',
  253. fn: function (){
  254. var self=this;
  255. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  256. return $core.withContext(function($ctx1) {
  257. //>>excludeEnd("ctx");
  258. var $1;
  259. $1=$recv(self._todos())._reject_((function(each){
  260. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  261. return $core.withContext(function($ctx2) {
  262. //>>excludeEnd("ctx");
  263. return $recv(each)._at_("done");
  264. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  265. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  266. //>>excludeEnd("ctx");
  267. }));
  268. return $1;
  269. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  270. }, function($ctx1) {$ctx1.fill(self,"todosNotDone",{},$globals.AppModel)});
  271. //>>excludeEnd("ctx");
  272. },
  273. //>>excludeStart("ide", pragmas.excludeIdeData);
  274. args: [],
  275. source: "todosNotDone\x0a ^self todos reject: [ :each | each at: 'done' ]",
  276. referencedClasses: [],
  277. //>>excludeEnd("ide");
  278. messageSends: ["reject:", "todos", "at:"]
  279. }),
  280. $globals.AppModel);
  281. $core.addMethod(
  282. $core.method({
  283. selector: "classDoneXxx",
  284. protocol: '*Trapped-Todo',
  285. fn: function (){
  286. var self=this;
  287. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  288. return $core.withContext(function($ctx1) {
  289. //>>excludeEnd("ctx");
  290. var $1;
  291. $1=self._dataToView_((function(carrier){
  292. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  293. return $core.withContext(function($ctx2) {
  294. //>>excludeEnd("ctx");
  295. return $recv($recv(carrier)._target())._class_("done-".__comma($recv(carrier)._value()));
  296. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  297. }, function($ctx2) {$ctx2.fillBlock({carrier:carrier},$ctx1,1)});
  298. //>>excludeEnd("ctx");
  299. }));
  300. return $1;
  301. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  302. }, function($ctx1) {$ctx1.fill(self,"classDoneXxx",{},$globals.TrappedProcessor.klass)});
  303. //>>excludeEnd("ctx");
  304. },
  305. //>>excludeStart("ide", pragmas.excludeIdeData);
  306. args: [],
  307. 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 ]",
  308. referencedClasses: [],
  309. //>>excludeEnd("ide");
  310. messageSends: ["dataToView:", "class:", "target", ",", "value"]
  311. }),
  312. $globals.TrappedProcessor.klass);
  313. });