Trapped-Demo.deploy.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. define("gh_herby_trapped/Trapped-Demo", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "gh_herby_trapped/Trapped-Backend", "amber/Kernel-Objects", "amber/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.addMethod(
  6. smalltalk.method({
  7. selector: "initialize",
  8. fn: function (){
  9. var self=this;
  10. function $SimpleKeyedPubSub(){return smalltalk.SimpleKeyedPubSub||(typeof SimpleKeyedPubSub=="undefined"?nil:SimpleKeyedPubSub)}
  11. function $AppModel(){return smalltalk.AppModel||(typeof AppModel=="undefined"?nil:AppModel)}
  12. return smalltalk.withContext(function($ctx1) {
  13. smalltalk.App.superclass.fn.prototype._initialize.apply(_st(self), []);
  14. self._dispatcher_(_st($SimpleKeyedPubSub())._new());
  15. self._model_(_st(_st($AppModel())._new())._title_("Todo"));
  16. _st((function(){
  17. return smalltalk.withContext(function($ctx2) {
  18. return self._modify_do_([["todos"]],(function(){
  19. return smalltalk.withContext(function($ctx3) {
  20. 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)])];
  21. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
  22. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._valueWithTimeout_((2000));
  23. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.App)})},
  24. messageSends: ["initialize", "dispatcher:", "new", "model:", "title:", "valueWithTimeout:", "modify:do:", "->"]}),
  25. smalltalk.App);
  26. smalltalk.addClass('AppModel', smalltalk.Object, ['title', 'todos', 'todoText'], 'Trapped-Demo');
  27. smalltalk.addMethod(
  28. smalltalk.method({
  29. selector: "addTodo",
  30. fn: function (){
  31. var self=this;
  32. return smalltalk.withContext(function($ctx1) {
  33. _st(self._todos())._add_(smalltalk.HashedCollection._from_(["text".__minus_gt(self._todoText()),"done".__minus_gt(false)]));
  34. self._todoText_("");
  35. return self}, function($ctx1) {$ctx1.fill(self,"addTodo",{},smalltalk.AppModel)})},
  36. messageSends: ["add:", "->", "todoText", "todos", "todoText:"]}),
  37. smalltalk.AppModel);
  38. smalltalk.addMethod(
  39. smalltalk.method({
  40. selector: "archive",
  41. fn: function (){
  42. var self=this;
  43. return smalltalk.withContext(function($ctx1) {
  44. self._todos_(self._todosNotDone());
  45. return self}, function($ctx1) {$ctx1.fill(self,"archive",{},smalltalk.AppModel)})},
  46. messageSends: ["todos:", "todosNotDone"]}),
  47. smalltalk.AppModel);
  48. smalltalk.addMethod(
  49. smalltalk.method({
  50. selector: "remaining",
  51. fn: function (){
  52. var self=this;
  53. return smalltalk.withContext(function($ctx1) {
  54. var $1;
  55. $1=_st(self._todosNotDone())._size();
  56. return $1;
  57. }, function($ctx1) {$ctx1.fill(self,"remaining",{},smalltalk.AppModel)})},
  58. messageSends: ["size", "todosNotDone"]}),
  59. smalltalk.AppModel);
  60. smalltalk.addMethod(
  61. smalltalk.method({
  62. selector: "title",
  63. fn: function (){
  64. var self=this;
  65. return smalltalk.withContext(function($ctx1) {
  66. var $1;
  67. $1=self["@title"];
  68. return $1;
  69. }, function($ctx1) {$ctx1.fill(self,"title",{},smalltalk.AppModel)})},
  70. messageSends: []}),
  71. smalltalk.AppModel);
  72. smalltalk.addMethod(
  73. smalltalk.method({
  74. selector: "title:",
  75. fn: function (aString){
  76. var self=this;
  77. return smalltalk.withContext(function($ctx1) {
  78. self["@title"]=aString;
  79. return self}, function($ctx1) {$ctx1.fill(self,"title:",{aString:aString},smalltalk.AppModel)})},
  80. messageSends: []}),
  81. smalltalk.AppModel);
  82. smalltalk.addMethod(
  83. smalltalk.method({
  84. selector: "todoText",
  85. fn: function (){
  86. var self=this;
  87. return smalltalk.withContext(function($ctx1) {
  88. var $1;
  89. $1=self["@todoText"];
  90. return $1;
  91. }, function($ctx1) {$ctx1.fill(self,"todoText",{},smalltalk.AppModel)})},
  92. messageSends: []}),
  93. smalltalk.AppModel);
  94. smalltalk.addMethod(
  95. smalltalk.method({
  96. selector: "todoText:",
  97. fn: function (aString){
  98. var self=this;
  99. return smalltalk.withContext(function($ctx1) {
  100. self["@todoText"]=aString;
  101. return self}, function($ctx1) {$ctx1.fill(self,"todoText:",{aString:aString},smalltalk.AppModel)})},
  102. messageSends: []}),
  103. smalltalk.AppModel);
  104. smalltalk.addMethod(
  105. smalltalk.method({
  106. selector: "todos",
  107. fn: function (){
  108. var self=this;
  109. return smalltalk.withContext(function($ctx1) {
  110. var $1;
  111. $1=self["@todos"];
  112. return $1;
  113. }, function($ctx1) {$ctx1.fill(self,"todos",{},smalltalk.AppModel)})},
  114. messageSends: []}),
  115. smalltalk.AppModel);
  116. smalltalk.addMethod(
  117. smalltalk.method({
  118. selector: "todos:",
  119. fn: function (anArray){
  120. var self=this;
  121. return smalltalk.withContext(function($ctx1) {
  122. self["@todos"]=anArray;
  123. return self}, function($ctx1) {$ctx1.fill(self,"todos:",{anArray:anArray},smalltalk.AppModel)})},
  124. messageSends: []}),
  125. smalltalk.AppModel);
  126. smalltalk.addMethod(
  127. smalltalk.method({
  128. selector: "todosNotDone",
  129. fn: function (){
  130. var self=this;
  131. return smalltalk.withContext(function($ctx1) {
  132. var $1;
  133. $1=_st(self._todos())._reject_((function(each){
  134. return smalltalk.withContext(function($ctx2) {
  135. return _st(each)._at_("done");
  136. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  137. return $1;
  138. }, function($ctx1) {$ctx1.fill(self,"todosNotDone",{},smalltalk.AppModel)})},
  139. messageSends: ["reject:", "at:", "todos"]}),
  140. smalltalk.AppModel);
  141. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  142. smalltalk.addMethod(
  143. smalltalk.method({
  144. selector: "renderOn:",
  145. fn: function (html){
  146. var self=this;
  147. return smalltalk.withContext(function($ctx1) {
  148. var $1,$2,$3,$4,$5,$6,$7,$9,$10,$11,$12,$8;
  149. []._trapDescend_((function(snap){
  150. return smalltalk.withContext(function($ctx2) {
  151. _st(_st(html)._h2())._trap_([["title"]]);
  152. return _st(_st(html)._div())._trap_toggle_ifNotPresent_([["todos"]],(function(){
  153. return smalltalk.withContext(function($ctx3) {
  154. return _st(snap)._do_((function(){
  155. return smalltalk.withContext(function($ctx4) {
  156. _st(_st(html)._span())._trap_([["remaining"]]);
  157. _st(html)._with_(" of ");
  158. _st(_st(html)._span())._trap_([["todos"], ["size"]]);
  159. _st(html)._with_(" remaining [ ");
  160. $1=_st(html)._a();
  161. _st($1)._href_("");
  162. _st($1)._onClick_((function(){
  163. return smalltalk.withContext(function($ctx5) {
  164. _st(snap)._modify_((function(model){
  165. return smalltalk.withContext(function($ctx6) {
  166. return _st(model)._archive();
  167. }, function($ctx6) {$ctx6.fillBlock({model:model},$ctx5)})}));
  168. return false;
  169. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  170. $2=_st($1)._with_("archive");
  171. $2;
  172. _st(html)._with_(" ]");
  173. _st(_st(html)._ul())._with_((function(){
  174. return smalltalk.withContext(function($ctx5) {
  175. return _st(html)._trapIter_tag_do_([["todos"]],"li",(function(each){
  176. return smalltalk.withContext(function($ctx6) {
  177. _st(_st(html)._root())._empty();
  178. $3=_st(html)._input();
  179. _st($3)._type_("checkbox");
  180. $4=_st($3)._trap_(["done"]);
  181. $4;
  182. $5=_st(html)._span();
  183. _st($5)._trap_read_(["done"],(function(model){
  184. return smalltalk.withContext(function($ctx7) {
  185. return _st(_st(html)._root())._class_("done-".__comma(model));
  186. }, function($ctx7) {$ctx7.fillBlock({model:model},$ctx6)})}));
  187. $6=_st($5)._trap_(["text"]);
  188. return $6;
  189. }, function($ctx6) {$ctx6.fillBlock({each:each},$ctx5)})}));
  190. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  191. $7=_st(html)._form();
  192. _st($7)._onSubmit_((function(){
  193. return smalltalk.withContext(function($ctx5) {
  194. _st(snap)._modify_((function(model){
  195. return smalltalk.withContext(function($ctx6) {
  196. return _st(model)._addTodo();
  197. }, function($ctx6) {$ctx6.fillBlock({model:model},$ctx5)})}));
  198. return false;
  199. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  200. $8=_st($7)._with_((function(){
  201. return smalltalk.withContext(function($ctx5) {
  202. $9=_st(html)._input();
  203. _st($9)._type_("text");
  204. _st($9)._trap_([["todoText"]]);
  205. _st($9)._at_put_("size",(30));
  206. $10=_st($9)._placeholder_("add new todo here");
  207. $10;
  208. $11=_st(html)._input();
  209. _st($11)._class_("btn-primary");
  210. _st($11)._type_("submit");
  211. $12=_st($11)._value_("add");
  212. return $12;
  213. }, function($ctx5) {$ctx5.fillBlock({},$ctx4)})}));
  214. return $8;
  215. }, function($ctx4) {$ctx4.fillBlock({},$ctx3)})}));
  216. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}),(function(){
  217. return smalltalk.withContext(function($ctx3) {
  218. return _st(html)._with_("Loading ...");
  219. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
  220. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1)})}));
  221. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.AppView)})},
  222. 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"]}),
  223. smalltalk.AppView);
  224. });