IObserver The interface definition for a PureMVC Observer.

In PureMVC, IObserver implementors assume these responsibilities:

  • Encapsulate the notification (callback) method of the interested object.

  • Encapsulate the notification context (self) of the interested object.

  • Provide methods for setting the interested object notification method and context.

  • Provide a method for notifying the interested object.

PureMVC does not rely upon underlying event models such as the one provided with Flash, and ActionScript 3 does not have an inherent event model.

The Observer Pattern as implemented within PureMVC exists to support event driven communication between the application and the actors of the MVC triad.

An Observer is an object that encapsulates information about an interested object with a notification method that should be called when an INotification is broadcast. The Observer then acts as a proxy for notifying the interested object.

Observers can receive Notifications by having their notifyObserver method invoked, passing in an object implementing the INotification interface, such as a subclass of Notification.

IObserver

interface IObserver {
    notifyContext?: any;
    notifyMethod?: null | ((notification: INotification) => void);
    compareNotifyContext(object: any): boolean;
    notifyObserver(notification: INotification): void;
}

Implemented by

Properties

notifyContext?: any

The context in which the notification method should be called.

notifyMethod?: null | ((notification: INotification) => void)

The method to be called when a notification is received.

Methods

  • Compare the given object to the notification context object.

    Parameters

    • object: any

      The object to compare with the notifyContext.

    Returns boolean

    true if the object is the same as the notifyContext, otherwise false.

  • Notify the interested object.

    Parameters

    • notification: INotification

      the INotification to pass to the interested object's notification method

    Returns void