Implements a basic approach to the observer pattern, but geared less for just vidya and more for general things.
So a good way to use this library is to subclass the Signalable for your given situation and then just overload notify for it. This will let you pass a reference or any custom data you need to event subscribers - so:
type myObject* = ref object somedata*: string someint*: int # Signals mySignal*: mySignalable mySignalable* = ref object of Signalable reference*: myObject method notify*(self: mySignalable) = for listener in self.listeners: listener.on_notify(self)
Types
Signalable = ref object of RootObj listeners*: seq[Listener]
Listener = ref object of RootObj
Methods
method on_notify(self: Listener; entity: Signalable) {...}{.base, raises: [], tags: [].}
- Base method for Listeners called when the signal they are listening to is emitted.
method notify(self: Signalable) {...}{.base, raises: [], tags: [].}
- Base method for Signalable called to emit to all Listeners.
method connect(self: Signalable; listener: Listener) {...}{.base, raises: [], tags: [].}
- Add a new Listener to this Signalable.
method connect(self: Signalable; listeners: openArray[Listener]) {...}{.inline, base, raises: [], tags: [].}
- Add an array of new Listeners to this Signalable.
method remove(self: Signalable; listener: Listener) {...}{.base, raises: [], tags: [].}
- Remove a Listener from this Signalable.
method remove(self: Signalable; listeners: openArray[Listener]) {...}{.inline, base, raises: [], tags: [].}
- Remove an array of Listeners from this Signalable.
Templates
template standard_impl(name: untyped): untyped