2
0

Examples.js 4.2 KB

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