Controller

Controller

new Controller()

A Multiton Controller implementation.

In PureMVC, the `Controller` class follows the 'Command and Controller' strategy, and assumes these responsibilities:

  • Remembering which `Command`s are intended to handle which `Notifications`.
  • Registering itself as an `Observer` with the `View` for each `Notification` that it has a `Command` mapping for.
  • Creating a new instance of the proper `Command` to handle a given `Notification` when notified by the `View`.
  • Calling the `Command`'s `execute` method, passing in the `Notification`.

Your application must register `Commands` with the Controller.

The simplest way is to subclass `Facade`, and use its `initializeController` method to add your registrations.

Source:
See:
  • View View
  • Observer Observer
  • Notification Notification
  • SimpleCommand SimpleCommand
  • MacroCommand MacroCommand

Members

(static) instanceMap :Map.<string, Controller>

Source:
Type:

(static) MULTITON_MSG :string

Message Constants

Source:
Type:
  • string

(protected) commandMap :Map.<string, function(): SimpleCommand>

Source:
Type:

(protected) multitonKey :string

Source:
Type:
  • string

(protected) view :View

Source:
Type:

Methods

(static) getInstance(key, factory) → {Controller}

Controller Multiton Factory method.

Source:
Parameters:
Name Type Description
key string
factory function
Returns:
Type:
Controller

the Multiton instance of Controller

(static) removeController(key)

Remove a Controller instance

Source:
Parameters:
Name Type Description
key string

of Controller instance to remove

executeCommand(notification)

If a `Command` has previously been registered to handle the given `Notification`, then it is executed.

Source:
Parameters:
Name Type Description
notification Notification

a Notification

hasCommand(notificationName) → {boolean}

Check if a Command is registered for a given Notification

Source:
Parameters:
Name Type Description
notificationName string
Returns:
Type:
boolean

whether a Command is currently registered for the given notificationName.

initializeController()

Initialize the Multiton Controller instance.

Called automatically by the constructor.

Note that if you are using a subclass of `View` in your application, you should also subclass `Controller` and override the `initializeController` method in the following way:

`
		// ensure that the Controller is talking to my View implementation
		initializeController( )
		{
			this.view = MyView.getInstance(this.multitonKey, (key) => new MyView(key));
		}
`
Source:

registerCommand(notificationName, factory)

Register a particular `Command` class as the handler for a particular `Notification`.

If an `Command` has already been registered to handle `Notification`s with this name, it is no longer used, the new `Command` is used instead.

The Observer for the new Command is only created if this the first time a Command has been registered for this Notification name.

Source:
Parameters:
Name Type Description
notificationName

the name of the Notification

factory function

removeCommand(notificationName)

Remove a previously registered Command to Notification mapping.

Source:
Parameters:
Name Type Description
notificationName string

the name of the Notification to remove the Command mapping for

Controller

new Controller(key)

Constructor.

This `Controller` 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 `Controller.getInstance( multitonKey )`

Source:
Parameters:
Name Type Description
key string
Throws:

Error if instance for this Multiton key has already been constructed

Type
Error

Members

(static) instanceMap :Map.<string, Controller>

Source:
Type:

(static) MULTITON_MSG :string

Message Constants

Source:
Type:
  • string

(protected) commandMap :Map.<string, function(): SimpleCommand>

Source:
Type:

(protected) multitonKey :string

Source:
Type:
  • string

(protected) view :View

Source:
Type:

Methods

(static) getInstance(key, factory) → {Controller}

Controller Multiton Factory method.

Source:
Parameters:
Name Type Description
key string
factory function
Returns:
Type:
Controller

the Multiton instance of Controller

(static) removeController(key)

Remove a Controller instance

Source:
Parameters:
Name Type Description
key string

of Controller instance to remove

executeCommand(notification)

If a `Command` has previously been registered to handle the given `Notification`, then it is executed.

Source:
Parameters:
Name Type Description
notification Notification

a Notification

hasCommand(notificationName) → {boolean}

Check if a Command is registered for a given Notification

Source:
Parameters:
Name Type Description
notificationName string
Returns:
Type:
boolean

whether a Command is currently registered for the given notificationName.

initializeController()

Initialize the Multiton Controller instance.

Called automatically by the constructor.

Note that if you are using a subclass of `View` in your application, you should also subclass `Controller` and override the `initializeController` method in the following way:

`
		// ensure that the Controller is talking to my View implementation
		initializeController( )
		{
			this.view = MyView.getInstance(this.multitonKey, (key) => new MyView(key));
		}
`
Source:

registerCommand(notificationName, factory)

Register a particular `Command` class as the handler for a particular `Notification`.

If an `Command` has already been registered to handle `Notification`s with this name, it is no longer used, the new `Command` is used instead.

The Observer for the new Command is only created if this the first time a Command has been registered for this Notification name.

Source:
Parameters:
Name Type Description
notificationName

the name of the Notification

factory function

removeCommand(notificationName)

Remove a previously registered Command to Notification mapping.

Source:
Parameters:
Name Type Description
notificationName string

the name of the Notification to remove the Command mapping for