A base Multiton Facade implementation.

Facade

Implements

Constructors

  • Constructor.

    This Facade implementation is a Multiton, so you should not call the constructor directly, but instead call the static Factory method, passing the unique key for this instance Facade.getInstance(multitonKey)

    Parameters

    • key: string

    Returns Facade

    Error if instance for this Multiton key has already been constructed

Properties

controller?: IController

Reference to Controller

model?: IModel

Reference to Model

multitonKey: string

The Multiton Key for this Core

view?: IView

Reference to View

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

Multiton Instances

MULTITON_MSG: string = "Facade instance for this Multiton key already constructed!"

Message Constants

Methods

  • Check if a Command is registered for a given Notification

    Parameters

    • notificationName: string

      The name of the notification to check.

    Returns boolean

    true if a command is registered for the notification; otherwise, false.

  • Check if a Mediator is registered or not

    Parameters

    • mediatorName: string

      The name of the mediator to check.

    Returns boolean

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

  • Check if a Proxy is registered

    Parameters

    • proxyName: string

      The name of the proxy to check.

    Returns boolean

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

  • Initialize the Controller.

    Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

    • You wish to initialize a different Controller.
    • You have Commands to register with the Controller at startup.`.

    If you don't want to initialize a different Controller, call super.initializeController() at the beginning of your method, then register Commands.

    Returns void

  • Initialize the Multiton Facade instance.

    Called automatically by the constructor. Override in your subclass to do any subclass specific initializations. Be sure to call super.initializeFacade(), though.

    Returns void

  • Initialize the Model.

    Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

    • You wish to initialize a different Model.
    • You have Proxys to register with the Model that do not retrieve a reference to the Facade at construction time.`

    If you don't want to initialize a different Model, call super.initializeModel() at the beginning of your method, then register Proxys.

    Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Proxys with the Model, since Proxys with mutable data will likely need to send Notifications and thus will likely want to fetch a reference to the Facade during their construction.

    Returns void

  • Set the Multiton key for this facade instance.

    Not called directly, but instead from the constructor when getInstance is invoked. It is necessary to be public in order to implement Notifier.

    Parameters

    • key: string

      The unique key to identify this instance of the notifier.

    Returns void

  • Initialize the View.

    Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

    • You wish to initialize a different View.
    • You have Observers to register with the View

    If you don't want to initialize a different View, call super.initializeView() at the beginning of your method, then register Mediator instances.

    Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Mediators with the View, since Mediator instances will need to send Notifications and thus will likely want to fetch a reference to the Facade during their construction.

    Returns void

  • Notify Observers.

    This method is left public mostly for backward compatibility, and to allow you to send custom notification classes using the facade.

    Usually you should just call sendNotification and pass the parameters, never having to construct the notification yourself.

    Parameters

    • notification: INotification

      The notification to be sent to observers.

    Returns void

  • Register a Command with the Controller by Notification name. *

    Parameters

    • notificationName: string

      The name of the notification to associate with the command.

    • factory: (() => ICommand)

      A factory function that returns an instance of ICommand. This function is used to create the command.

    Returns void

  • Remove a previously registered Command to Notification mapping from the Controller.

    Parameters

    • notificationName: string

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

    Returns void

  • Remove a Proxy from the Model by name.

    Parameters

    • proxyName: string

      The name of the proxy to remove.

    Returns null | IProxy

    The removed proxy instance, or null if no such proxy exists.

  • Retrieve a Proxy from the Model by name.

    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.

  • Retrieve a Proxy from the Model by name.

    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.

  • Create and send an Notification.

    Keeps us from having to construct new notification instances in our implementation code.

    Parameters

    • notificationName: string

      The name of the notification to be sent.

    • Optionalbody: any

      Optional data to be included with the notification.

    • Optionaltype: string

      Optional type of the notification.

    Returns void

  • Facade Multiton Factory method

    Parameters

    • key: string

      The unique key associated with the instance of the facade.

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

      A factory function that creates a new instance of the facade. It takes the key as a parameter and returns an IFacade instance.

    Returns IFacade

    the Multiton instance of the Facade

  • Check if a Core is registered or not

    Parameters

    • key: string

      The unique key to check for an existing facade instance.

    Returns boolean

    true if a facade instance exists for the key; otherwise, false.

  • Remove a Core.

    Remove the Model, View, Controller and Facade instances for the given key.

    Parameters

    • key: string

      The unique key associated with the facade instance to be removed.

    Returns void