Examples.js 4.6 KB

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