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
(protected) commandMap :Map.<string, function(): SimpleCommand>
- Source:
Type:
-
Map.<string, function(): SimpleCommand>
Methods
(static) getInstance(key, factory) → {Controller}
Controller
Multiton Factory method.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
|
factory |
function
|
(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 |
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 |
|
factory |
function
|
removeCommand(notificationName)
Remove a previously registered Command
to Notification
mapping.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
notificationName |
string
|
the name of the |