Trapped-Demo.deploy.js 6.7 KB

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