1
0

Kernel-Announcements.st 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Smalltalk current createPackage: 'Kernel-Announcements' properties: #{}!
  2. Object subclass: #AnnouncementSubscription
  3. instanceVariableNames: 'block announcementClass'
  4. package: 'Kernel-Announcements'!
  5. !AnnouncementSubscription methodsFor: 'accessing'!
  6. announcementClass
  7. ^announcementClass
  8. !
  9. announcementClass: aClass
  10. announcementClass := aClass
  11. !
  12. block
  13. ^block
  14. !
  15. block: aBlock
  16. block := aBlock
  17. ! !
  18. !AnnouncementSubscription methodsFor: 'announcing'!
  19. deliver: anAnnouncement
  20. (self handlesAnnouncement: anAnnouncement)
  21. ifTrue: [self block value: anAnnouncement]
  22. !
  23. handlesAnnouncement: anAnnouncement
  24. ^anAnnouncement isKindOf: self announcementClass
  25. ! !
  26. Object subclass: #Announcer
  27. instanceVariableNames: 'registry subscriptions'
  28. package: 'Kernel-Announcements'!
  29. !Announcer methodsFor: 'announcing'!
  30. announce: anAnnouncement
  31. subscriptions do: [:each |
  32. each deliver: anAnnouncement]
  33. ! !
  34. !Announcer methodsFor: 'initialization'!
  35. initialize
  36. super initialize.
  37. subscriptions := Array new
  38. ! !
  39. !Announcer methodsFor: 'subscribing'!
  40. on: aClass do: aBlock
  41. subscriptions add: (AnnouncementSubscription new
  42. block: aBlock;
  43. announcementClass: aClass;
  44. yourself)
  45. ! !