2
0

Examples.js 4.6 KB

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