Namespace mmir.ModelManager
Defined in: modelManager.js.
Constructor Attributes | Constructor Name and Description |
---|---|
A class for managing the models of the application (MVC-Component).
|
Method Attributes | Method Name and Description |
---|---|
getModel(modelName)
This function gets the model by name.
|
|
This function returns all loaded models.
|
|
This function returns all loaded models.
|
|
init(callbackFunction)
This function must be called before using the mmir.ModelManager.
|
Namespace Detail
mmir.ModelManager
A class for managing the models of the application (MVC-Component).
It's purpose is to load the models automatically. This "class" is a singleton - so that only one instance is in use.
TODO add example for usage (models as "class" / models as "singleton")
It's purpose is to load the models automatically. This "class" is a singleton - so that only one instance is in use.
TODO add example for usage (models as "class" / models as "singleton")
- Requires:
- jQuery.Deferred
Method Detail
getInstance()
- Deprecated:
- use ModelManager object directly, e.g. instead of: mmir.ModelManager.getInstance().getModel() use: mmir.ModelManager.getModel() NOTE: ModelManager must be initialized before it can be used.
{Object}
getModel(modelName)
This function gets the model by name.
- Parameters:
- {String} modelName
- Name of the model which should be returned
- Returns:
- {Object} The model if found, null else
{Array}
getModelNames()
This function returns all loaded models.
- Returns:
- {Array
} all loaded model names
{Array}
getModels()
This function returns all loaded models.
- Returns:
- {Array} All loaded models
{Promise}
init(callbackFunction)
This function must be called before using the mmir.ModelManager. The Initialization process is asynchronous,
because javascript-files must be loaded (the models), so it forces a synchronous behavior by using
a callback function containing the instructions, which rely on the presence of the loaded models.
It loads the models and then calls the callback functions and returns the instance of this class.
It loads the models and then calls the callback functions and returns the instance of this class.
Note:
The callback function should contain all (!) instructions which require the prior loading of the models.
The callback mechanism is necessary, because loading the models is asynchronous.
If provided, the callback function is invoked with 1 argument, the ModelManager instance:
NOTE: use EITHER callback-function OR returned Promise -- do not use both!
The callback mechanism is necessary, because loading the models is asynchronous.
If provided, the callback function is invoked with 1 argument, the ModelManager instance:
callbackFunction(modelManagerInstance)
function afterLoadingModels(modelManagerInstance){ var userModel = modelManagerInstance.getModel('User'); //do something... } mmir.ModelManager.create(afterLoadingModels);
- Parameters:
- {Function} callbackFunction Optional
- The function which should be called after loading all controllers
- Returns:
- {Promise} a Deferred.promise that gets fulfilled when models are loaded.