Trapped-Demo.deploy.js 7.9 KB

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