1 class:: NotificationCenter
2 summary:: let an object emit notifications
3 related:: Classes/SimpleController, Classes/NodeWatcher
7 One common OOP pattern is Model-View-Controller where one object (the controller) is a dependant of the model. Every time the model changes it notifies all of its dependants. In this case the model has a dictionary of dependants and iterates through those.
9 Another common pattern is NotificationCenter wherein an object emits a notification and clients can register functions that will be executed when that notification happens.
11 A link::Classes/Server:: emits a \newAllocators notification when it creates new node and bus allocators which it does when it quits or boots.
14 NotificationCenter.notify(Server.default, \newAllocators);
17 You can listen for this:
20 NotificationCenter.register(Server.default, \newAllocators, yourself, {
21 // throw away all your node variables
26 The link::Classes/Buffer:: class register a function to clear its info cache whenever a server restarts. The server is emiting changed messages quite often (every 0.4 secs for the status updates), and the Buffer class is only interested in boot/quit events, so this is a more lightweight system for this purpose.
33 The object emits a message and may also pass extra args.
36 An interested client can register the action function for the object/message notification. A listener may only register one action per object/message notification.
39 Remove the registrations.
41 method::registerOneShot
42 After the notification has been emited and handled, automatically unregister.
44 method::registrationExists
45 Simply confirms if a registration is already in place.