1
0

Examples.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. define("amber_core/Examples", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/Canvas"], 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. globals.Counter.superclass.fn.prototype._initialize.apply(_st(self), []);
  52. self["@count"]=(0);
  53. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.Counter)})},
  54. args: [],
  55. source: "initialize\x0a\x09super initialize.\x0a\x09count := 0",
  56. messageSends: ["initialize"],
  57. referencedClasses: []
  58. }),
  59. globals.Counter);
  60. smalltalk.addMethod(
  61. smalltalk.method({
  62. selector: "renderOn:",
  63. protocol: 'rendering',
  64. fn: function (html){
  65. var self=this;
  66. return smalltalk.withContext(function($ctx1) {
  67. var $1,$2,$3,$4,$5,$6;
  68. $1=_st(html)._h1();
  69. _st($1)._with_(_st(self["@count"])._asString());
  70. $ctx1.sendIdx["with:"]=1;
  71. $2=_st($1)._yourself();
  72. self["@header"]=$2;
  73. $3=_st(html)._button();
  74. $ctx1.sendIdx["button"]=1;
  75. _st($3)._with_("++");
  76. $ctx1.sendIdx["with:"]=2;
  77. $4=_st($3)._onClick_((function(){
  78. return smalltalk.withContext(function($ctx2) {
  79. return self._increase();
  80. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  81. $ctx1.sendIdx["onClick:"]=1;
  82. $5=_st(html)._button();
  83. _st($5)._with_("--");
  84. $6=_st($5)._onClick_((function(){
  85. return smalltalk.withContext(function($ctx2) {
  86. return self._decrease();
  87. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  88. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},globals.Counter)})},
  89. args: ["html"],
  90. 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 ]",
  91. messageSends: ["with:", "h1", "asString", "yourself", "button", "onClick:", "increase", "decrease"],
  92. referencedClasses: []
  93. }),
  94. globals.Counter);
  95. smalltalk.addMethod(
  96. smalltalk.method({
  97. selector: "tryExample",
  98. protocol: 'example',
  99. fn: function (){
  100. var self=this;
  101. return smalltalk.withContext(function($ctx1) {
  102. _st(self._new())._appendToJQuery_("body"._asJQuery());
  103. return self}, function($ctx1) {$ctx1.fill(self,"tryExample",{},globals.Counter.klass)})},
  104. args: [],
  105. 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",
  106. messageSends: ["appendToJQuery:", "new", "asJQuery"],
  107. referencedClasses: []
  108. }),
  109. globals.Counter.klass);
  110. });