A Multiton 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 Multiton, so you should not call the constructor directly, but instead call the static Multiton Factory method Model.getInstance(multitonKey)

    Parameters

    • key: string

    Returns Model

    Error if instance for this Multiton key instance has already been constructed

Properties

multitonKey: string

The Multiton Key for this Core

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

Mapping of proxyNames to IProxy instances

instanceMap: {
    [key: string]: IModel;
} = {}

Multiton Instances

MULTITON_MSG: string = "Model instance for this Multiton key 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 Multiton instance in your subclass without overriding the constructor.

    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 Multiton Factory method.

    Parameters

    • key: string

      The key used to identify the model instance.

    • factory: ((key: string) => IModel)

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

    Returns IModel

    The model instance associated with the given key.

  • Remove a Model instance

    Parameters

    • key: string

      The key used to identify the model instance to be removed.

    Returns void