Examples.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. define("amber_core/Examples", ["amber/boot", "amber_core/Web"], function($boot){
  2. var smalltalk=$boot.vm,nil=$boot.nil,_st=$boot.asReceiver,globals=$boot.globals;
  3. smalltalk.addPackage('Examples');
  4. smalltalk.packages["Examples"].transport = {"type":"amd","amdNamespace":"amber_core"};
  5. smalltalk.addClass('Counter', globals.Widget, ['count', 'header'], 'Examples');
  6. 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";
  7. smalltalk.addMethod(
  8. smalltalk.method({
  9. selector: "decrease",
  10. protocol: 'actions',
  11. fn: function (){
  12. var self=this;
  13. return smalltalk.withContext(function($ctx1) {
  14. self["@count"]=_st(self["@count"]).__minus((1));
  15. _st(self["@header"])._contents_((function(html){
  16. return smalltalk.withContext(function($ctx2) {
  17. return _st(html)._with_(_st(self["@count"])._asString());
  18. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  19. }));
  20. return self}, function($ctx1) {$ctx1.fill(self,"decrease",{},globals.Counter)});
  21. },
  22. args: [],
  23. source: "decrease\x0a\x09count := count - 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  24. messageSends: ["-", "contents:", "with:", "asString"],
  25. referencedClasses: []
  26. }),
  27. globals.Counter);
  28. smalltalk.addMethod(
  29. smalltalk.method({
  30. selector: "increase",
  31. protocol: 'actions',
  32. fn: function (){
  33. var self=this;
  34. return smalltalk.withContext(function($ctx1) {
  35. self["@count"]=_st(self["@count"]).__plus((1));
  36. _st(self["@header"])._contents_((function(html){
  37. return smalltalk.withContext(function($ctx2) {
  38. return _st(html)._with_(_st(self["@count"])._asString());
  39. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  40. }));
  41. return self}, function($ctx1) {$ctx1.fill(self,"increase",{},globals.Counter)});
  42. },
  43. args: [],
  44. source: "increase\x0a\x09count := count + 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  45. messageSends: ["+", "contents:", "with:", "asString"],
  46. referencedClasses: []
  47. }),
  48. globals.Counter);
  49. smalltalk.addMethod(
  50. smalltalk.method({
  51. selector: "initialize",
  52. protocol: 'initialization',
  53. fn: function (){
  54. var self=this;
  55. return smalltalk.withContext(function($ctx1) {
  56. ($ctx1.supercall = true, globals.Counter.superclass.fn.prototype._initialize.apply(_st(self), []));
  57. $ctx1.supercall = false;
  58. self["@count"]=(0);
  59. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.Counter)});
  60. },
  61. args: [],
  62. source: "initialize\x0a\x09super initialize.\x0a\x09count := 0",
  63. messageSends: ["initialize"],
  64. referencedClasses: []
  65. }),
  66. globals.Counter);
  67. smalltalk.addMethod(
  68. smalltalk.method({
  69. selector: "renderOn:",
  70. protocol: 'rendering',
  71. fn: function (html){
  72. var self=this;
  73. return smalltalk.withContext(function($ctx1) {
  74. var $1,$2,$3,$4,$5,$6;
  75. $1=_st(html)._h1();
  76. _st($1)._with_(_st(self["@count"])._asString());
  77. $ctx1.sendIdx["with:"]=1;
  78. $2=_st($1)._yourself();
  79. self["@header"]=$2;
  80. $3=_st(html)._button();
  81. $ctx1.sendIdx["button"]=1;
  82. _st($3)._with_("++");
  83. $ctx1.sendIdx["with:"]=2;
  84. $4=_st($3)._onClick_((function(){
  85. return smalltalk.withContext(function($ctx2) {
  86. return self._increase();
  87. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  88. }));
  89. $ctx1.sendIdx["onClick:"]=1;
  90. $5=_st(html)._button();
  91. _st($5)._with_("--");
  92. $6=_st($5)._onClick_((function(){
  93. return smalltalk.withContext(function($ctx2) {
  94. return self._decrease();
  95. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  96. }));
  97. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},globals.Counter)});
  98. },
  99. args: ["html"],
  100. 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 ]",
  101. messageSends: ["with:", "h1", "asString", "yourself", "button", "onClick:", "increase", "decrease"],
  102. referencedClasses: []
  103. }),
  104. globals.Counter);
  105. smalltalk.addMethod(
  106. smalltalk.method({
  107. selector: "tryExample",
  108. protocol: 'example',
  109. fn: function (){
  110. var self=this;
  111. return smalltalk.withContext(function($ctx1) {
  112. _st(self._new())._appendToJQuery_("body"._asJQuery());
  113. return self}, function($ctx1) {$ctx1.fill(self,"tryExample",{},globals.Counter.klass)});
  114. },
  115. args: [],
  116. 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 appendToJQuery: 'body' asJQuery",
  117. messageSends: ["appendToJQuery:", "new", "asJQuery"],
  118. referencedClasses: []
  119. }),
  120. globals.Counter.klass);
  121. });