Class: ControllerManager

mmir. ControllerManager

new mmir.ControllerManager()

A class for managing the controllers of the application.
It's purpose is to load the controllers and their views / partials and provide functions to find controllers or perform actions or helper-actions. This "class" is structured as a singleton - so that only one instance is in use.

Methods

get(ctrlName){Object}

This function gets the controller by name.
Name Type Description
ctrlName String Name of the controller which should be returned
Returns:
if found, null else
This function returns names of all loaded controllers.
Returns:
of all loaded controllers

init(callback, ctx){Promise}

This function must be called before using the mmir.ControllerManager. The Initialization process is asynchronous, because javascript-files must be loaded (the controllers). To ensure that the ControllerManager is initialized, a callback can be used, or the returned Promise (i.e. a "then-able" object) for code, that relies on the presence of the loaded controllers.
Note: The callback function should be used for code, that requires the prior loading of the controllers.
The callback mechanism is necessary, because loading the controllers is asynchronous.

If provided, the callback function is invoked with 1 argument, the ControllerManager instance:
callbackFunction(controllerManagerInstance)
Name Type Description
callback function optional OPTIONAL an optional callback that will be triggered after the controllers where loaded
ctx Object optional OPTIONAL the context for the controller & helper implementations (DEFAULT: the global context, i.e. window)
Returns:
deferred promise that will get fulfilled when controllers are loaded
Example
//recommended style:
 mmir.require(['mmirf/controllerManager', ...], function(controllerManager, ...) {
 	controllerManager.init().then(function(theInitializedControllerInstance){
 		...
 	});
 })
 
 //old style:
	function afterLoadingControllers(controllerManagerInstance){
		var appCtrl = controllerManagerInstance.get('Application');
		//do something...
	} 
	mmir.ctrl.init(afterLoadingControllers);

perform(ctrlName, actionName, data){Object}

This function performs an action of a controller.
Name Type Description
ctrlName String Name of the controller to which the action belongs
actionName String Name of the action that should be performed
data Object optional data that can be submitted to the action
Returns:
return object of the performed action

performHelper(ctrlName, actionName, data){Object}

This function performs an action of a helper-class for a controller.
Name Type Description
ctrlName String Name of the controller to which the helper action belongs
actionName String Name of the action that should be performed by the helper
data Object optional data that can be submitted to the action
Returns:
return object of the performed action