2
0

Kernel-Announcements.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. smalltalk.addPackage('Kernel-Announcements', {});
  2. smalltalk.addClass('AnnouncementSubscription', smalltalk.Object, ['block', 'announcementClass'], 'Kernel-Announcements');
  3. smalltalk.addMethod(
  4. "_announcementClass",
  5. smalltalk.method({
  6. selector: "announcementClass",
  7. category: 'accessing',
  8. fn: function (){
  9. var self=this;
  10. return self['@announcementClass'];
  11. return self;},
  12. args: [],
  13. source: "announcementClass\x0a\x09^announcementClass",
  14. messageSends: [],
  15. referencedClasses: []
  16. }),
  17. smalltalk.AnnouncementSubscription);
  18. smalltalk.addMethod(
  19. "_announcementClass_",
  20. smalltalk.method({
  21. selector: "announcementClass:",
  22. category: 'accessing',
  23. fn: function (aClass){
  24. var self=this;
  25. (self['@announcementClass']=aClass);
  26. return self;},
  27. args: ["aClass"],
  28. source: "announcementClass: aClass\x0a\x09announcementClass := aClass",
  29. messageSends: [],
  30. referencedClasses: []
  31. }),
  32. smalltalk.AnnouncementSubscription);
  33. smalltalk.addMethod(
  34. "_block",
  35. smalltalk.method({
  36. selector: "block",
  37. category: 'accessing',
  38. fn: function (){
  39. var self=this;
  40. return self['@block'];
  41. return self;},
  42. args: [],
  43. source: "block\x0a\x09^block",
  44. messageSends: [],
  45. referencedClasses: []
  46. }),
  47. smalltalk.AnnouncementSubscription);
  48. smalltalk.addMethod(
  49. "_block_",
  50. smalltalk.method({
  51. selector: "block:",
  52. category: 'accessing',
  53. fn: function (aBlock){
  54. var self=this;
  55. (self['@block']=aBlock);
  56. return self;},
  57. args: ["aBlock"],
  58. source: "block: aBlock\x0a\x09block := aBlock",
  59. messageSends: [],
  60. referencedClasses: []
  61. }),
  62. smalltalk.AnnouncementSubscription);
  63. smalltalk.addMethod(
  64. "_deliver_",
  65. smalltalk.method({
  66. selector: "deliver:",
  67. category: 'announcing',
  68. fn: function (anAnnouncement){
  69. var self=this;
  70. ((($receiver = smalltalk.send(self, "_handlesAnnouncement_", [anAnnouncement])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(smalltalk.send(self, "_block", []), "_value_", [anAnnouncement]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){return smalltalk.send(smalltalk.send(self, "_block", []), "_value_", [anAnnouncement]);})]));
  71. return self;},
  72. args: ["anAnnouncement"],
  73. source: "deliver: anAnnouncement\x0a\x09(self handlesAnnouncement: anAnnouncement)\x0a\x09\x09ifTrue: [self block value: anAnnouncement]",
  74. messageSends: ["ifTrue:", "handlesAnnouncement:", "value:", "block"],
  75. referencedClasses: []
  76. }),
  77. smalltalk.AnnouncementSubscription);
  78. smalltalk.addMethod(
  79. "_handlesAnnouncement_",
  80. smalltalk.method({
  81. selector: "handlesAnnouncement:",
  82. category: 'announcing',
  83. fn: function (anAnnouncement){
  84. var self=this;
  85. return smalltalk.send(anAnnouncement, "_isKindOf_", [smalltalk.send(self, "_announcementClass", [])]);
  86. return self;},
  87. args: ["anAnnouncement"],
  88. source: "handlesAnnouncement: anAnnouncement\x0a\x09^anAnnouncement isKindOf: self announcementClass",
  89. messageSends: ["isKindOf:", "announcementClass"],
  90. referencedClasses: []
  91. }),
  92. smalltalk.AnnouncementSubscription);
  93. smalltalk.addClass('Announcer', smalltalk.Object, ['registry', 'subscriptions'], 'Kernel-Announcements');
  94. smalltalk.addMethod(
  95. "_announce_",
  96. smalltalk.method({
  97. selector: "announce:",
  98. category: 'announcing',
  99. fn: function (anAnnouncement){
  100. var self=this;
  101. smalltalk.send(self['@subscriptions'], "_do_", [(function(each){return smalltalk.send(each, "_deliver_", [anAnnouncement]);})]);
  102. return self;},
  103. args: ["anAnnouncement"],
  104. source: "announce: anAnnouncement\x0a\x09subscriptions do: [:each |\x0a\x09\x09each deliver: anAnnouncement]",
  105. messageSends: ["do:", "deliver:"],
  106. referencedClasses: []
  107. }),
  108. smalltalk.Announcer);
  109. smalltalk.addMethod(
  110. "_initialize",
  111. smalltalk.method({
  112. selector: "initialize",
  113. category: 'initialization',
  114. fn: function (){
  115. var self=this;
  116. smalltalk.send(self, "_initialize", [], smalltalk.Announcer.superclass || nil);
  117. (self['@subscriptions']=smalltalk.send((smalltalk.Array || Array), "_new", []));
  118. return self;},
  119. args: [],
  120. source: "initialize\x0a\x09super initialize.\x0a\x09subscriptions := Array new",
  121. messageSends: ["initialize", "new"],
  122. referencedClasses: ["Array"]
  123. }),
  124. smalltalk.Announcer);
  125. smalltalk.addMethod(
  126. "_on_do_",
  127. smalltalk.method({
  128. selector: "on:do:",
  129. category: 'subscribing',
  130. fn: function (aClass, aBlock){
  131. var self=this;
  132. smalltalk.send(self['@subscriptions'], "_add_", [(function($rec){smalltalk.send($rec, "_block_", [aBlock]);smalltalk.send($rec, "_announcementClass_", [aClass]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send((smalltalk.AnnouncementSubscription || AnnouncementSubscription), "_new", []))]);
  133. return self;},
  134. args: ["aClass", "aBlock"],
  135. source: "on: aClass do: aBlock\x0a\x09subscriptions add: (AnnouncementSubscription new\x0a\x09\x09block: aBlock;\x0a\x09\x09announcementClass: aClass;\x0a\x09\x09yourself)",
  136. messageSends: ["add:", "block:", "announcementClass:", "yourself", "new"],
  137. referencedClasses: ["AnnouncementSubscription"]
  138. }),
  139. smalltalk.Announcer);