Trapped-Demo.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. category: 'initialization',
  8. fn: function (){
  9. var self=this;
  10. var obj;
  11. smalltalk.send(self,"_initialize",[],smalltalk.TrappedMWIsolated);
  12. smalltalk.send(self,"_dispatcher_",[smalltalk.send((smalltalk.TrappedDumbDispatcher || TrappedDumbDispatcher),"_new",[])]);
  13. obj=smalltalk.HashedCollection._fromPairs_([smalltalk.send("title","__minus_gt",["To-Do List"])]);
  14. smalltalk.send(self,"_model_",[obj]);
  15. smalltalk.send((function(){
  16. smalltalk.send(obj,"_at_put_",["items",["hello", "world"]]);
  17. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[[]]);
  18. }),"_valueWithTimeout_",[(2000)]);
  19. return self},
  20. args: [],
  21. source: "initialize\x0a\x09| obj |\x0a\x09super initialize.\x0a self dispatcher: TrappedDumbDispatcher new.\x0a obj := #{'title' -> 'To-Do List'}.\x0a self model: obj.\x0a [ obj at: 'items' put: #('hello' 'world'). self dispatcher changed: #() ] valueWithTimeout: 2000\x0a",
  22. messageSends: ["initialize", "dispatcher:", "new", "->", "model:", "valueWithTimeout:", "at:put:", "changed:", "dispatcher"],
  23. referencedClasses: ["TrappedDumbDispatcher"]
  24. }),
  25. smalltalk.App);
  26. smalltalk.addClass('AppView', smalltalk.Widget, [], 'Trapped-Demo');
  27. smalltalk.addMethod(
  28. "_renderOn_",
  29. smalltalk.method({
  30. selector: "renderOn:",
  31. category: 'rendering',
  32. fn: function (html){
  33. var self=this;
  34. var $1,$2;
  35. smalltalk.send(smalltalk.send(html,"_h2",[]),"_trapShow_",[["title"]]);
  36. smalltalk.send(smalltalk.send(html,"_div",[]),"_trap_toggle_ifNotPresent_",[["items"],(function(){
  37. smalltalk.send(smalltalk.send(html,"_p",[]),"_with_",[(function(){
  38. smalltalk.send(smalltalk.send(html,"_span",[]),"_trapShow_",[[smalltalk.symbolFor("size")]]);
  39. return smalltalk.send(html,"_with_",[" item(s)."]);
  40. })]);
  41. return smalltalk.send(smalltalk.send(html,"_form",[]),"_with_",[(function(){
  42. return smalltalk.send(smalltalk.send(html,"_ul",[]),"_trapIter_tag_do_",[[],smalltalk.symbolFor("li"),(function(each){
  43. $1=smalltalk.send(html,"_input",[]);
  44. smalltalk.send($1,"_type_",["checkbox"]);
  45. $2=smalltalk.send($1,"_at_put_",["checked",true]);
  46. $2;
  47. return smalltalk.send(html,"_with_",[each]);
  48. })]);
  49. })]);
  50. }),(function(){
  51. return smalltalk.send(html,"_with_",["Loading ..."]);
  52. })]);
  53. return self},
  54. args: ["html"],
  55. source: "renderOn: html\x0a\x09html h2 trapShow: #('title').\x0a html div trap: #('items') toggle: [\x0a html p with: [ html span trapShow: #(#size). html with: ' item(s).' ].\x0a\x09\x09html form with: [ html ul trapIter: #() tag: #li do: [ :each |\x0a html input\x0a type: 'checkbox';\x0a at: 'checked' put: true.\x0a html with: each\x0a ]]\x0a ] ifNotPresent: [ html with: 'Loading ...' ]",
  56. messageSends: ["trapShow:", "h2", "trap:toggle:ifNotPresent:", "with:", "span", "p", "trapIter:tag:do:", "type:", "input", "at:put:", "ul", "form", "div"],
  57. referencedClasses: []
  58. }),
  59. smalltalk.AppView);
  60. smalltalk.addClass('TrappedDumbDispatcher', smalltalk.TrappedDispatcher, ['queue'], 'Trapped-Demo');
  61. smalltalk.addMethod(
  62. "_add_",
  63. smalltalk.method({
  64. selector: "add:",
  65. category: 'accessing',
  66. fn: function (aSubscription){
  67. var self=this;
  68. smalltalk.send(self["@queue"],"_add_",[aSubscription]);
  69. return self},
  70. args: ["aSubscription"],
  71. source: "add: aSubscription\x0a\x09queue add: aSubscription.\x0a",
  72. messageSends: ["add:"],
  73. referencedClasses: []
  74. }),
  75. smalltalk.TrappedDumbDispatcher);
  76. smalltalk.addMethod(
  77. "_clean",
  78. smalltalk.method({
  79. selector: "clean",
  80. category: 'bookkeeping',
  81. fn: function (){
  82. var self=this;
  83. self["@queue"]=smalltalk.send(self["@queue"],"_select_",[(function(each){
  84. return smalltalk.send(each,"_isEnabled",[]);
  85. })]);
  86. return self},
  87. args: [],
  88. source: "clean\x0a\x09queue := queue select: [ :each | each isEnabled ]",
  89. messageSends: ["select:", "isEnabled"],
  90. referencedClasses: []
  91. }),
  92. smalltalk.TrappedDumbDispatcher);
  93. smalltalk.addMethod(
  94. "_do_",
  95. smalltalk.method({
  96. selector: "do:",
  97. category: 'enumeration',
  98. fn: function (aBlock){
  99. var self=this;
  100. smalltalk.send(self["@queue"],"_do_",[aBlock]);
  101. return self},
  102. args: ["aBlock"],
  103. source: "do: aBlock\x0a\x09queue do: aBlock",
  104. messageSends: ["do:"],
  105. referencedClasses: []
  106. }),
  107. smalltalk.TrappedDumbDispatcher);
  108. smalltalk.addMethod(
  109. "_initialize",
  110. smalltalk.method({
  111. selector: "initialize",
  112. category: 'initialization',
  113. fn: function (){
  114. var self=this;
  115. self["@queue"]=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
  116. return self},
  117. args: [],
  118. source: "initialize\x0a\x09queue := OrderedCollection new",
  119. messageSends: ["new"],
  120. referencedClasses: ["OrderedCollection"]
  121. }),
  122. smalltalk.TrappedDumbDispatcher);