Namespace: ModuleElementUtils

Oracle® JavaScript Extension Toolkit (JET)
16.1.0

F92237-01

Since:
  • 5.0.0
Module:
  • ojmodule-element-utils

QuickNav

Description

Utility methods for oj-module element

ModuleElementUtils is a helper object that provides convenience methods for creating views, view models or entire oj-module configuration objects using RequireJS.

Conventions

View

  • Views should have .html extension.
  • In addition to loading the view, both the createView() and createConfig() methods will convert the loaded view into an array of nodes, as expected by oj-module.

View Model

  • ViewModel modules should have .js extension.
  • The view model is loaded as an AMD module and the value is expected to be either a constructor function or an object - a view model instance.
  • See descriptions of the createViewModel() and createConfig() methods for details on how the loaded module is handled.

Create configuration object using createView() and createViewModel()


//define oj-module config as a Promise that resolves into a configuration object
self.moduleConfig = Promise.all([
  moduleElementUtils.createView({'viewPath':'views/dashboard/page.html'}),
  moduleElementUtils.createViewModel({'viewModelPath':'viewModels/dashboard/page'})
 ])
 .then(
   function(values){
     return {'view':values[0],'viewModel':values[1]};
   },
   function(reason){}
 );

Create configuration object using createConfig()


//define oj-module config as a Promise that resolves into a configuration object
self.moduleConfig = moduleElementUtils.createConfig({ name: 'dashboard/page', params: {value:'A'} });


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. The initialize 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. Use viewPath and viewModelPath 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