Examples.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. define(["amber/boot", "require", "amber/web/Web"], function($boot,requirejs){"use strict";
  2. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. var $pkg = $core.addPackage("Examples");
  4. $pkg.transport = {"type":"amd","amdNamespace":"amber/legacy"};
  5. $core.addClass("Counter", $globals.Widget, "Examples");
  6. $core.setSlots($globals.Counter, ["count", "header"]);
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.Counter.comment="This is a trivial Widget example mimicking the classic Counter example in Seaside.\x0aIn order to play with it, just evaluate the doit below in a workspace.\x0aThen take a look in the HTML document above the IDE.\x0a\x0a\x09\x09Counter tryExample";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "decrease",
  13. protocol: "actions",
  14. //>>excludeStart("ide", pragmas.excludeIdeData);
  15. args: [],
  16. source: "decrease\x0a\x09count := count - 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  17. referencedClasses: [],
  18. //>>excludeEnd("ide");
  19. pragmas: [],
  20. messageSends: ["-", "contents:", "with:", "asString"]
  21. }, function ($methodClass){ return function (){
  22. var self=this,$self=this;
  23. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  24. return $core.withContext(function($ctx1) {
  25. //>>excludeEnd("ctx");
  26. $self.count=$recv($self.count).__minus((1));
  27. $recv($self.header)._contents_((function(html){
  28. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  29. return $core.withContext(function($ctx2) {
  30. //>>excludeEnd("ctx");
  31. return $recv(html)._with_($recv($self.count)._asString());
  32. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  33. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  34. //>>excludeEnd("ctx");
  35. }));
  36. return self;
  37. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  38. }, function($ctx1) {$ctx1.fill(self,"decrease",{})});
  39. //>>excludeEnd("ctx");
  40. }; }),
  41. $globals.Counter);
  42. $core.addMethod(
  43. $core.method({
  44. selector: "increase",
  45. protocol: "actions",
  46. //>>excludeStart("ide", pragmas.excludeIdeData);
  47. args: [],
  48. source: "increase\x0a\x09count := count + 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  49. referencedClasses: [],
  50. //>>excludeEnd("ide");
  51. pragmas: [],
  52. messageSends: ["+", "contents:", "with:", "asString"]
  53. }, function ($methodClass){ return function (){
  54. var self=this,$self=this;
  55. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  56. return $core.withContext(function($ctx1) {
  57. //>>excludeEnd("ctx");
  58. $self.count=$recv($self.count).__plus((1));
  59. $recv($self.header)._contents_((function(html){
  60. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  61. return $core.withContext(function($ctx2) {
  62. //>>excludeEnd("ctx");
  63. return $recv(html)._with_($recv($self.count)._asString());
  64. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  65. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  66. //>>excludeEnd("ctx");
  67. }));
  68. return self;
  69. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  70. }, function($ctx1) {$ctx1.fill(self,"increase",{})});
  71. //>>excludeEnd("ctx");
  72. }; }),
  73. $globals.Counter);
  74. $core.addMethod(
  75. $core.method({
  76. selector: "initialize",
  77. protocol: "initialization",
  78. //>>excludeStart("ide", pragmas.excludeIdeData);
  79. args: [],
  80. source: "initialize\x0a\x09super initialize.\x0a\x09count := 0",
  81. referencedClasses: [],
  82. //>>excludeEnd("ide");
  83. pragmas: [],
  84. messageSends: ["initialize"]
  85. }, function ($methodClass){ return function (){
  86. var self=this,$self=this;
  87. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  88. return $core.withContext(function($ctx1) {
  89. //>>excludeEnd("ctx");
  90. [(
  91. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  92. $ctx1.supercall = true,
  93. //>>excludeEnd("ctx");
  94. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._initialize.call($self))
  95. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  96. ,$ctx1.supercall = false
  97. //>>excludeEnd("ctx");
  98. ][0];
  99. $self.count=(0);
  100. return self;
  101. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  102. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  103. //>>excludeEnd("ctx");
  104. }; }),
  105. $globals.Counter);
  106. $core.addMethod(
  107. $core.method({
  108. selector: "renderOn:",
  109. protocol: "rendering",
  110. //>>excludeStart("ide", pragmas.excludeIdeData);
  111. args: ["html"],
  112. source: "renderOn: html\x0a\x09header := html h1\x0a\x09\x09with: count asString;\x0a\x09\x09yourself.\x0a\x09html button\x0a\x09\x09with: '++';\x0a\x09\x09onClick: [ self increase ].\x0a\x09html button\x0a\x09\x09with: '--';\x0a\x09\x09onClick: [ self decrease ]",
  113. referencedClasses: [],
  114. //>>excludeEnd("ide");
  115. pragmas: [],
  116. messageSends: ["with:", "h1", "asString", "yourself", "button", "onClick:", "increase", "decrease"]
  117. }, function ($methodClass){ return function (html){
  118. var self=this,$self=this;
  119. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  120. return $core.withContext(function($ctx1) {
  121. //>>excludeEnd("ctx");
  122. var $1,$2,$3;
  123. $1=$recv(html)._h1();
  124. [$recv($1)._with_($recv($self.count)._asString())
  125. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  126. ,$ctx1.sendIdx["with:"]=1
  127. //>>excludeEnd("ctx");
  128. ][0];
  129. $self.header=$recv($1)._yourself();
  130. $2=[$recv(html)._button()
  131. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  132. ,$ctx1.sendIdx["button"]=1
  133. //>>excludeEnd("ctx");
  134. ][0];
  135. [$recv($2)._with_("++")
  136. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  137. ,$ctx1.sendIdx["with:"]=2
  138. //>>excludeEnd("ctx");
  139. ][0];
  140. [$recv($2)._onClick_((function(){
  141. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  142. return $core.withContext(function($ctx2) {
  143. //>>excludeEnd("ctx");
  144. return $self._increase();
  145. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  146. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  147. //>>excludeEnd("ctx");
  148. }))
  149. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  150. ,$ctx1.sendIdx["onClick:"]=1
  151. //>>excludeEnd("ctx");
  152. ][0];
  153. $3=$recv(html)._button();
  154. $recv($3)._with_("--");
  155. $recv($3)._onClick_((function(){
  156. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  157. return $core.withContext(function($ctx2) {
  158. //>>excludeEnd("ctx");
  159. return $self._decrease();
  160. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  161. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  162. //>>excludeEnd("ctx");
  163. }));
  164. return self;
  165. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  166. }, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html})});
  167. //>>excludeEnd("ctx");
  168. }; }),
  169. $globals.Counter);
  170. $core.addMethod(
  171. $core.method({
  172. selector: "tryExample",
  173. protocol: "example",
  174. //>>excludeStart("ide", pragmas.excludeIdeData);
  175. args: [],
  176. source: "tryExample\x0a\x09\x22In order to play with the Counter, just select the\x0a\x09doit below and press the Do it button. Then take a\x0a\x09look in the HTML document above the IDE.\x22\x0a\x0a\x09\x22Counter tryExample\x22\x0a\x09\x09self new appendToBrush: 'body' asBrush",
  177. referencedClasses: [],
  178. //>>excludeEnd("ide");
  179. pragmas: [],
  180. messageSends: ["appendToBrush:", "new", "asBrush"]
  181. }, function ($methodClass){ return function (){
  182. var self=this,$self=this;
  183. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  184. return $core.withContext(function($ctx1) {
  185. //>>excludeEnd("ctx");
  186. $recv($self._new())._appendToBrush_("body"._asBrush());
  187. return self;
  188. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  189. }, function($ctx1) {$ctx1.fill(self,"tryExample",{})});
  190. //>>excludeEnd("ctx");
  191. }; }),
  192. $globals.Counter.a$cls);
  193. });