Examples.js 4.3 KB

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