Examples.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. smalltalk.addPackage('Examples', {});
  2. smalltalk.addClass('Counter', smalltalk.Widget, ['count', 'header'], 'Examples');
  3. smalltalk.addMethod(
  4. unescape('_increase'),
  5. smalltalk.method({
  6. selector: unescape('increase'),
  7. category: 'actions',
  8. fn: function (){
  9. var self=this;
  10. self['@count']=((($receiver = self['@count']).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)]));
  11. smalltalk.send(self['@header'], "_contents_", [(function(html){return smalltalk.send(html, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);})]);
  12. return self;},
  13. args: [],
  14. source: unescape('increase%0A%20%20%20%20count%20%3A%3D%20count%20+%201.%0A%20%20%20%20header%20contents%3A%20%5B%3Ahtml%20%7C%20html%20with%3A%20count%20asString%5D'),
  15. messageSends: [unescape("+"), "contents:", "with:", "asString"],
  16. referencedClasses: []
  17. }),
  18. smalltalk.Counter);
  19. smalltalk.addMethod(
  20. unescape('_decrease'),
  21. smalltalk.method({
  22. selector: unescape('decrease'),
  23. category: 'actions',
  24. fn: function (){
  25. var self=this;
  26. self['@count']=((($receiver = self['@count']).klass === smalltalk.Number) ? $receiver -(1) : smalltalk.send($receiver, "__minus", [(1)]));
  27. smalltalk.send(self['@header'], "_contents_", [(function(html){return smalltalk.send(html, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);})]);
  28. return self;},
  29. args: [],
  30. source: unescape('decrease%0A%20%20%20%20count%20%3A%3D%20count%20-%201.%0A%20%20%20%20header%20contents%3A%20%5B%3Ahtml%20%7C%20html%20with%3A%20count%20asString%5D'),
  31. messageSends: [unescape("-"), "contents:", "with:", "asString"],
  32. referencedClasses: []
  33. }),
  34. smalltalk.Counter);
  35. smalltalk.addMethod(
  36. unescape('_initialize'),
  37. smalltalk.method({
  38. selector: unescape('initialize'),
  39. category: 'initialization',
  40. fn: function (){
  41. var self=this;
  42. smalltalk.send(self, "_initialize", [], smalltalk.Widget);
  43. self['@count']=(0);
  44. return self;},
  45. args: [],
  46. source: unescape('initialize%0A%20%20%20%20super%20initialize.%0A%20%20%20%20count%20%3A%3D%200'),
  47. messageSends: ["initialize"],
  48. referencedClasses: []
  49. }),
  50. smalltalk.Counter);
  51. smalltalk.addMethod(
  52. unescape('_renderOn_'),
  53. smalltalk.method({
  54. selector: unescape('renderOn%3A'),
  55. category: 'rendering',
  56. fn: function (html){
  57. var self=this;
  58. self['@header']=(function($rec){smalltalk.send($rec, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(html, "_h1", []));
  59. (function($rec){smalltalk.send($rec, "_with_", [unescape("++")]);return smalltalk.send($rec, "_onClick_", [(function(){return smalltalk.send(self, "_increase", []);})]);})(smalltalk.send(html, "_button", []));
  60. (function($rec){smalltalk.send($rec, "_with_", [unescape("--")]);return smalltalk.send($rec, "_onClick_", [(function(){return smalltalk.send(self, "_decrease", []);})]);})(smalltalk.send(html, "_button", []));
  61. return self;},
  62. args: ["html"],
  63. source: unescape('renderOn%3A%20html%0A%20%20%20%20header%20%3A%3D%20html%20h1%20%0A%09with%3A%20count%20asString%3B%0A%09yourself.%0A%20%20%20%20html%20button%0A%09with%3A%20%27++%27%3B%0A%09onClick%3A%20%5Bself%20increase%5D.%0A%20%20%20%20html%20button%0A%09with%3A%20%27--%27%3B%0A%09onClick%3A%20%5Bself%20decrease%5D'),
  64. messageSends: ["with:", "asString", "yourself", "h1", "onClick:", "increase", "button", "decrease"],
  65. referencedClasses: []
  66. }),
  67. smalltalk.Counter);