XUINotificationCenter
Description
This module provides a global mechanism for sending in-app notifications (essentially messages
between objects in your app) in the form of a XUINotification
.
Properties
Name | Type | Read-Only |
---|---|---|
mDispatchQueue() | XUINotification |
|
mDispatchTimer | Timer |
|
mKeyListenerDictionary | Dictionary |
|
mUnregistering | Boolean |
Methods
Name | Parameters | Returns |
---|---|---|
DispatchTimerAction | sender As Timer |
|
ListenForKey | listener As XUINotificationListener , key As String |
|
ListenForKeys | listener As XUINotificationListener , keys() As String |
|
NormaliseKey | key As String |
String |
Register | key As String , listener As XUINotificationListener |
|
RemoveDeadReferences | references() As WeakRef |
|
Send | sender As Variant , key As String , data As Variant |
|
StopListening | listener As XUINotificationListener |
|
StopListeningForKey | listener As XUINotificationListener , key As String |
|
Unregister | listener As XUINotificationListener |
|
UnregisterForKey | listener As XUINotificationListener , key As String |
|
UnregisterForKeys | listener As XUINotificationListener , keys() As String |
Constants
Name | Type |
---|---|
DISPATCH_INTERVAL_MILLISECONDS | Double |
DISPATCH_INTERVAL_MILLISECONDS As Double The number of milliseconds between checks for new messages to send.
Property Descriptions
mDispatchQueue() As XUINotification
The queue of notifications that require sending.
mDispatchTimer As Timer
The timer used to dispatch notifications.
mKeyListenerDictionary As Dictionary
Key = Notification Key (String), Value = NKListener (WeakRef).
mUnregistering As Boolean
True if NotificationKit is in the middle of unregistering a listener.
Method Descriptions
DispatchTimerAction(sender As Timer)
Delegate method, called by the internal timer, that actually dispatches the notifications.
sender
is the timer whose Action
event fired.
ListenForKey(listener As XUINotificationListener, key As String)
Registers the listener
to listen for notifications with the key
.
ListenForKeys(listener As XUINotificationListener, keys() As String)
Registers the listener
to listen for notifications with the specified keys
.
NormaliseKey(key As String) As String
Normalises key
so it doesn't break subsequent regex queries.
Keys can be hierarchical with children separated by a .
Wildcard matching is permitted with *
Examples:
Prefs
Matches the key Prefs
only.
Prefs.Editor
matches Prefs.Editor
only.
Prefs.*
matches Prefs.Editor
, Prefs.Compiler
, etc.
Prefs.Editor.*
matches Prefs.Editor.Colours
, Prefs.Editor.Fonts
, etc.
Register(key As String, listener As XUINotificationListener)
Registers listener
to be notified whenever a notification with key
occurs.
RemoveDeadReferences(references() As WeakRef)
Removes any dead references from the array of weak references.
Send(sender As Variant, key As String, data As Variant)
Creates and queues the passed notification for sending.
StopListening(listener As XUINotificationListener)
Stops listener
from listening to all notifications.
StopListeningForKey(listener As XUINotificationListener, key As String)
Stops listener
from listening to notifications with key
.
Unregister(listener As XUINotificationListener)
Unregisters listener
from all notifications.
UnregisterForKey(listener As XUINotificationListener, key As String)
Unregisters listener
from notifications with key
.
UnregisterForKeys(listener As XUINotificationListener, keys() As String)
Unregisters listener
from notifications with the specified keys
.
Examples
Let's suppose you have an instance of a class (sender
) that periodically sends out a notification.
This could be accomplished like so:
NotificationCenter.Send("MyKey", someValue)
Will will also imagine that we have an instance of a class (listener
) that wants to listen for these notifications.
This is easily achieved:
listener.Register("MyKey")
Now whenever sender
calls NotificationCenter.Send()
with "MyKey"
as the key, listener
's
NotificationReceived()
method is invoked by the notification center.