Skip to content
Aaron edited this page Feb 11, 2019 · 1 revision

The primary design goal is to eliminate object creation on high frequency events.

In a nutshell, you subscribe to all events a node emits by passing an implementation of DSISubscriber to DSNode.subscribe.

There is no programmatic way to learn what events are available but it is a future consideration.

Default Events

DSNode node has several built in events, they are:

  • DSNode.CHILD_ADDED
  • DSNode.CHILD_REMOVED
  • DSNode.CHILD_RENAMED
  • DSNode.METADATA_CHANGED
  • DSNode.VALUE_CHANGED

Those are the string constants representing the ID of those events, there are also corresponding *_EVENT constants representing singleton DSEvent instances.

DSNode subclasses can add additional events. For example DSConnection has DSConnection.CONNECTED and DSConnection.DISCONNECTED.

Creating Events

A node can add any events it wants. The node should declare and document the String event ID constant. If the event is a singleton instance (it should be), that should be a public constant as well.

Events should be as granular as possible so the subscriber does not have to query anything but the event ID to understand the type of event. This is for future linking of events to other objects such as actions without requiring interleaving logic to invoke the action.

To dispatch events, simply call DSNode.fire.

Filtering Events

Subscribers can receive all kinds of events from a node. If the subscriber is only interested in a subset of events, the subscriber is responsible for filtering. DSEventFilter is a simple filter that can be used for this purpose.

Clone this wiki locally