A Singleton Model implementation.

In PureMVC, the Model class provides access to model objects (Proxies) by named lookup.

The Model assumes these responsibilities:

  • Maintain a cache of Proxy instances.
  • Provide methods for registering, retrieving, and removing Proxy instances.

Your application must register Proxy instances with the Model. Typically, you use an Command to create and register Proxy instances once the Facade has initialized the Core actors.

Proxy

Model

Implements

Constructors

  • Constructor.

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

    Returns Model

    Error if instance for this Singleton instance has already been constructed

Properties

proxyMap: {
    [key: string]: IProxy;
}

Mapping of proxyNames to IProxy instances

instance: IModel

Singleton instance

SINGLETON_MSG: string = "Model Singleton already constructed!"

Message Constants

Methods

  • Check if a Proxy is registered

    Parameters

    • proxyName: string

      The name of the proxy to check.

    Returns boolean

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

  • Initialize the Model instance.

    Called automatically by the constructor, this is your opportunity to initialize the Singleton instance in your subclass without overriding the constructor.

    Returns void

  • Register a Proxy with the Model.

    Parameters

    • proxy: IProxy

      The proxy instance to be registered.

    Returns void

  • Remove a Proxy from the Model.

    Parameters

    • proxyName: string

      The name of the proxy to be removed.

    Returns null | IProxy

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

  • Retrieve a Proxy from the Model.

    Parameters

    • proxyName: string

      The name of the proxy to retrieve.

    Returns null | IProxy

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

  • Model Singleton Factory method.

    Parameters

    • factory: (() => IModel)

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

    Returns IModel

    The Singleton instance.