Disclosed is a method which uses pseudo-events to ensure that a system immediately notifies observers when a property’s state changes.
Page 01 of 1
Using Pseudo-Events to Ensure that Observers are Notified of a Property 's State
When using an Observer pattern for property-change events, an event is normally fired only when the value of a property changes. However, it is often the case that an observer is registering because they want to be kept aware of the value of a given property at all times. This often requires that observers implement a two-step process: act on the current value of the property, and then subscribe to a property-change event in order to act again when if the property is changed.
The disclosed solution is to have the observable immediately fire a psuedo-event when a user subscribes to a property. This is an event that appears to the observer as a normal property-change, but is visible only to the observer that is currently subscribing; it is not propagated to any other observers. This allows the observer to specify their behavior only once by subscribing to the property with a handler that implements the desired behavior.
Upon an observer subscribing to a property-change event, the system immediately calls the provided callback, passing the current value of the property. It does not fire a normal property-change event at this time, because as far as any other observers are concerned, the property has not changed. From the point of view of the new observer, the property's value is, conceptually, different from what that observer knew it to be before, which is "unknown".
1