Trapped-Demo.js 14 KB

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