Trapped-Demo.deploy.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. messageSends: ["initialize", "dispatcher:", "new", "model:", "title:", "valueWithTimeout:", "modify:do:", "->"]}),
  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. messageSends: ["add:", "->", "todoText", "todos", "todoText:"]}),
  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. messageSends: ["todos:", "todosNotDone"]}),
  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. messageSends: ["size", "todosNotDone"]}),
  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. messageSends: []}),
  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. messageSends: []}),
  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. messageSends: []}),
  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. messageSends: []}),
  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. messageSends: []}),
  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. messageSends: []}),
  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. messageSends: ["reject:", "at:", "todos"]}),
  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) { _st(snap)._modify_((function(model){
  154. return smalltalk.withContext(function($ctx6) { return _st(model)._archive();
  155. }, function($ctx6) {$ctx6.fillBlock({model:model},$ctx1)})}));
  156. return false;
  157. }, function($ctx5) {$ctx5.fillBlock({},$ctx1)})}));
  158. $2=_st($1)._with_("archive");
  159. $2;
  160. _st(html)._with_(" ]");
  161. _st(_st(html)._ul())._with_((function(){
  162. return smalltalk.withContext(function($ctx5) { return _st(html)._trapIter_tag_do_([smalltalk.symbolFor("todos")],smalltalk.symbolFor("li"),(function(each){
  163. return smalltalk.withContext(function($ctx6) { _st(_st(html)._root())._empty();
  164. $3=_st(html)._input();
  165. _st($3)._type_("checkbox");
  166. $4=_st($3)._trap_(["done"]);
  167. $4;
  168. $5=_st(html)._span();
  169. _st($5)._trap_read_(["done"],(function(model){
  170. return smalltalk.withContext(function($ctx7) { return _st(_st(html)._root())._class_(_st("done-").__comma(model));
  171. }, function($ctx7) {$ctx7.fillBlock({model:model},$ctx1)})}));
  172. $6=_st($5)._trap_(["text"]);
  173. return $6;
  174. }, function($ctx6) {$ctx6.fillBlock({each:each},$ctx1)})}));
  175. }, function($ctx5) {$ctx5.fillBlock({},$ctx1)})}));
  176. $7=_st(html)._form();
  177. _st($7)._onSubmit_((function(){
  178. return smalltalk.withContext(function($ctx5) { _st(snap)._modify_((function(model){
  179. return smalltalk.withContext(function($ctx6) { return _st(model)._addTodo();
  180. }, function($ctx6) {$ctx6.fillBlock({model:model},$ctx1)})}));
  181. return false;
  182. }, function($ctx5) {$ctx5.fillBlock({},$ctx1)})}));
  183. $8=_st($7)._with_((function(){
  184. return smalltalk.withContext(function($ctx5) { $9=_st(html)._input();
  185. _st($9)._type_("text");
  186. _st($9)._trap_([smalltalk.symbolFor("todoText")]);
  187. _st($9)._at_put_("size",(30));
  188. $10=_st($9)._placeholder_("add new todo here");
  189. $10;
  190. $11=_st(html)._input();
  191. _st($11)._class_("btn-primary");
  192. _st($11)._type_("submit");
  193. $12=_st($11)._value_("add");
  194. return $12;
  195. }, function($ctx5) {$ctx5.fillBlock({},$ctx1)})}));
  196. return $8;
  197. }, function($ctx4) {$ctx4.fillBlock({},$ctx1)})}));
  198. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}),(function(){
  199. return smalltalk.withContext(function($ctx3) { return _st(html)._with_("Loading ...");
  200. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  201. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1)})}));
  202. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.AppView)})},
  203. 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"]}),
  204. smalltalk.AppView);