Kernel-Announcements.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. },
  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. },
  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. var $1;
  71. $1=smalltalk.send(self,"_handlesAnnouncement_",[anAnnouncement]);
  72. if(smalltalk.assert($1)){
  73. smalltalk.send(smalltalk.send(self,"_block",[]),"_value_",[anAnnouncement]);
  74. };
  75. return self},
  76. args: ["anAnnouncement"],
  77. source: "deliver: anAnnouncement\x0a\x09(self handlesAnnouncement: anAnnouncement)\x0a\x09\x09ifTrue: [self block value: anAnnouncement]",
  78. messageSends: ["ifTrue:", "value:", "block", "handlesAnnouncement:"],
  79. referencedClasses: []
  80. }),
  81. smalltalk.AnnouncementSubscription);
  82. smalltalk.addMethod(
  83. "_handlesAnnouncement_",
  84. smalltalk.method({
  85. selector: "handlesAnnouncement:",
  86. category: 'announcing',
  87. fn: function (anAnnouncement){
  88. var self=this;
  89. var $1;
  90. $1=smalltalk.send(anAnnouncement,"_isKindOf_",[smalltalk.send(self,"_announcementClass",[])]);
  91. return $1;
  92. },
  93. args: ["anAnnouncement"],
  94. source: "handlesAnnouncement: anAnnouncement\x0a\x09^anAnnouncement isKindOf: self announcementClass",
  95. messageSends: ["isKindOf:", "announcementClass"],
  96. referencedClasses: []
  97. }),
  98. smalltalk.AnnouncementSubscription);
  99. smalltalk.addClass('Announcer', smalltalk.Object, ['registry', 'subscriptions'], 'Kernel-Announcements');
  100. smalltalk.addMethod(
  101. "_announce_",
  102. smalltalk.method({
  103. selector: "announce:",
  104. category: 'announcing',
  105. fn: function (anAnnouncement){
  106. var self=this;
  107. smalltalk.send(self["@subscriptions"],"_do_",[(function(each){
  108. return smalltalk.send(each,"_deliver_",[anAnnouncement]);
  109. })]);
  110. return self},
  111. args: ["anAnnouncement"],
  112. source: "announce: anAnnouncement\x0a\x09subscriptions do: [:each |\x0a\x09\x09each deliver: anAnnouncement]",
  113. messageSends: ["do:", "deliver:"],
  114. referencedClasses: []
  115. }),
  116. smalltalk.Announcer);
  117. smalltalk.addMethod(
  118. "_initialize",
  119. smalltalk.method({
  120. selector: "initialize",
  121. category: 'initialization',
  122. fn: function (){
  123. var self=this;
  124. smalltalk.send(self,"_initialize",[],smalltalk.Object);
  125. self["@subscriptions"]=smalltalk.send((smalltalk.Array || Array),"_new",[]);
  126. return self},
  127. args: [],
  128. source: "initialize\x0a\x09super initialize.\x0a\x09subscriptions := Array new",
  129. messageSends: ["initialize", "new"],
  130. referencedClasses: ["Array"]
  131. }),
  132. smalltalk.Announcer);
  133. smalltalk.addMethod(
  134. "_on_do_",
  135. smalltalk.method({
  136. selector: "on:do:",
  137. category: 'subscribing',
  138. fn: function (aClass,aBlock){
  139. var self=this;
  140. var $1,$2;
  141. $1=smalltalk.send((smalltalk.AnnouncementSubscription || AnnouncementSubscription),"_new",[]);
  142. smalltalk.send($1,"_block_",[aBlock]);
  143. smalltalk.send($1,"_announcementClass_",[aClass]);
  144. $2=smalltalk.send($1,"_yourself",[]);
  145. smalltalk.send(self["@subscriptions"],"_add_",[$2]);
  146. return self},
  147. args: ["aClass", "aBlock"],
  148. source: "on: aClass do: aBlock\x0a\x09subscriptions add: (AnnouncementSubscription new\x0a\x09\x09block: aBlock;\x0a\x09\x09announcementClass: aClass;\x0a\x09\x09yourself)",
  149. messageSends: ["add:", "block:", "new", "announcementClass:", "yourself"],
  150. referencedClasses: ["AnnouncementSubscription"]
  151. }),
  152. smalltalk.Announcer);