A Singleton View implementation.

In PureMVC, the View class assumes these responsibilities:

  • Maintain a cache of Mediator instances.
  • Provide methods for registering, retrieving, and removing Mediators.
  • Notifying Mediators when they are registered or removed.
  • Managing the observer lists for each Notification in the application.
  • Providing a method for attaching Observers to a Notification's observer list.
  • Providing a method for broadcasting a Notification.
  • Notifying the Observers of a given Notification when it broadcast.

Implements

Constructors

  • Constructor.

    This View implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory method View.getInstance()

    Returns View

    Error if instance for this Singleton key has already been constructed

Properties

mediatorMap: {
    [key: string]: IMediator;
}

Mapping of Mediator names to Mediator instances

observerMap: {
    [key: string]: IObserver[];
}

Mapping of Notification names to Observer lists

instance: IView

Singleton instance

SINGLETON_MSG: string = "View Singleton already constructed!"

Message Constants

Methods

  • Check if a Mediator is registered or not

    Parameters

    • mediatorName: string

      The name of the mediator to check.

    Returns boolean

    true if a mediator with the specified name is registered; otherwise, false.

  • Notify the Observers for a particular Notification.

    All previously attached Observers for this Notification's list are notified and are passed a reference to the Notification in the order in which they were registered.

    Parameters

    • notification: INotification

      The notification containing the data or command details to be sent to observers.

    Returns void

  • Register a Mediator instance with the View.

    Registers the Mediator so that it can be retrieved by name, and further interrogates the Mediator for its Notification interests.

    If the Mediator returns any Notification names to be notified about, an Observer is created encapsulating the Mediator instance's handleNotification method and registering it as an Observer for all Notifications the Mediator is interested in.

    Parameters

    • mediator: IMediator

      The mediator instance to be registered.

    Returns void

  • Register an Observer to be notified of Notifications with a given name.

    Parameters

    • notificationName: string

      The name of the notification to which the observer should be registered.

    • observer: IObserver

      The observer instance to be registered.

    Returns void

  • Remove a Mediator from the View.

    Parameters

    • mediatorName: string

      The name of the mediator to be removed.

    Returns null | IMediator

    The removed mediator instance, or null if no mediator with the given name was found.

  • Remove the observer for a given notifyContext from an observer list for a given Notification name.

    Parameters

    • notificationName: string

      The name of the notification for which the observer should be removed.

    • notifyContext: object

      The context of the observer to be removed.

    Returns void

  • Retrieve a Mediator from the View.

    Parameters

    • mediatorName: string

      The name of the mediator to retrieve.

    Returns null | IMediator

    The mediator instance associated with the given name, or null if no such mediator exists.

  • View Singleton factory method.

    Parameters

    • factory: (() => IView)

      A factory function that creates a new instance of the view if one does not already exist.

    Returns IView

    The view instance.