A base Observer implementation.

An Observer is an object that encapsulates information about an interested object with a method that should be called when a particular Notification is broadcast.

In PureMVC, the Observer class assumes these responsibilities:

  • Encapsulate the notification (callback) method of the interested object.
  • Encapsulate the notification context (this) of the interested object.
  • Provide methods for setting the notification method and context.
  • Provide a method for notifying the interested object.

Observer

Implements

Constructors

  • Constructor.

    The notification method on the interested object should take one parameter of type Notification

    Parameters

    • Optionalnotify: null | ((notification: INotification) => void)

      The method to be called when a notification is received. Can be null.

    • Optionalcontext: any

      The context in which to call the notifyMethod. Can be null.

    Returns Observer

Accessors

  • get notifyContext(): any
  • Get the notifyContext

    Returns any

    The current context or null if no context is set.

  • set notifyContext(value): void
  • Set the notification context.

    Parameters

    • value: any

      The context to set. Can be null.

    Returns void

  • get notifyMethod(): undefined | null | ((notification: INotification) => void)
  • Get the notification method.

    Returns undefined | null | ((notification: INotification) => void)

    The current method or null if no method is set.

  • set notifyMethod(value): void
  • Set the notification method.

    The notification method should take one parameter of type Notification.

    Parameters

    • value: null | ((notification: INotification) => void)

      The method to set for handling notifications. Can be null.

    Returns void

Methods

  • Compare an object to the notification context.

    Parameters

    • object: any

      The object to compare with the observer's context.

    Returns boolean

    true if the context is the same, otherwise false.

  • Notify the interested object.

    Parameters

    • notification: INotification

      The notification to send to the observer.

    Returns void