Trapped-Demo.deploy.js 8.4 KB

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