Usage
Typescript Import Format
//This namespace exports multiple static methods or members. To import
import * as ModuleElementUtils from "ojs/ojmodule-element-utils";
//Now you can access the methods as ModuleElementUtils.methodName and so on
For additional information visit:
Methods
-
(static) .createConfig<P>(options: {name?: string, viewPath?: string, viewModelPath?: string, params?: P, require?: ((module: string)=> any)|((modules: string[], ready?: any, errback?: any)=> void)}):Promise<{view:Node[], viewModel:ModuleViewModel|null}>
-
Utility function for creating a configuration object for oj-module. This method uses the name or paths to load a view and a view model and constructs a configuration object for the oj-module element. Note, the view model is loaded as an AMD module. If the returned value is a function, it will be treated as a view model constructor; otherwise the returned value will be treated as a view model instance. When view model parameters are specified, they will be passed to the constructor or to the
initialize
method on the view model instance. Theinitialize
method on the view model is optional.Parameters:
Name Type Description options
Object Options object used to create a view model Properties
Name Type Argument Description name
string <optional>
View model name. If viewPath
option is omitted, the name is also going to be used for loading the view. The view and view model will be loaded using default paths - 'views/' and 'viewModels/'. The path is relative to the RequireJS baseURL. The text plugin will be used for loading the view. UseviewPath
andviewModelPath
when you want to load view and view model from different locations.viewPath
string <optional>
The path to the view, relative to the RequireJS baseURL. The text plugin will be used for loading the view. viewModelPath
string <optional>
The path to the model, relative to the RequireJS baseURL. require
((module: string)=> any) | ((modules: string[], ready?: any, errback?: any)=> void) <optional>
An optional instance of the require() function to be used for loading the view and view model. By default the path is relative to the baseUrl specified for the application require calls. params
P <optional>
Parameters object that will be passed either to the model constructor or to the initialize
method on the loaded model.- Since:
- 7.0.0
Returns:
A promise that resolves into a configuration object for oj-module.
- Type
- Promise
-
(static) .createView(options: {viewPath: string, require?: ((module: string)=> any)|((modules: string[], ready?: any, errback?: any)=> void)}):Promise<Node[]>
-
Utility function for creating a view to be used in configuration object for oj-module.
Parameters:
Name Type Description options
Object Options object used to create a view Properties
Name Type Argument Description viewPath
string The path to the view, relative to the RequireJS baseURL. The text plugin will be used for loading the view. require
((module: string)=> any) | ((modules: string[], ready?: any, errback?: any)=> void) <optional>
An optional instance of the require() function to be used for loading the view. By default the path is relative to the baseUrl specified for the application require calls. - Since:
- 5.0.0
Returns:
A promise that resolves into an array of DOM nodes
- Type
- Promise
-
(static) .createViewModel<P>(options: {viewModelPath: string, params?: P, require?: ((module: string)=> any)|((modules: string[], ready?: any, errback?: any)=> void),initialize?: 'always' | 'never' | 'ifParams'}):Promise<ModuleViewModel|Function>
-
Utility function for creating a view model to be used in configuration object for oj-module.
Parameters:
Name Type Description options
Object Options object used to create a view model Properties
Name Type Argument Description viewModelPath
string The path to the model, relative to the RequireJS baseURL. require
((module: string)=> any) | ((modules: string[], ready?: any, errback?: any)=> void) <optional>
An optional instance of the require() function to be used for loading the view model. By default the path is relative to the baseUrl specified for the application require calls. params
P <optional>
Parameters object that will be passed either to the model constructor or to the initialize
method on the loaded model.initialize
'always' | 'never' | 'ifParams' <optional>
valid values are "always", "never", "ifParams" (default) - always - the model will be instantiated from the constructor whether parameters are given or not.
- never - an instance or a constructor will be given to the application and the application is responsible for constructing the model instance.
- ifParams - the model will be instantiated from the constructor or
initialize
method will be called on the instance, when parameters object is specified.
- Since:
- 5.0.0
Returns:
A promise that contains either model instance or a model constructor. When the promise is resolved into a constructor, the application is responsible for constructing the model instance before passing it to the configuration object on the oj-module.
- Type
- Promise