Namespace: ModuleElementUtils

Oracle® JavaScript Extension Toolkit (JET)
7.1.0

F18183-01

QuickNav


PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

ModuleElementUtils

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

Module usage

See JET Module Loading for an overview of module usage within JET.

Javascript Import Format
define(['ojs/ojmodule-element-utils'], function(ModuleElementUtils) {
 // Application should call API on ModuleElementUtils 
})
Typescript Import Format
//This namespace exports multiple static methods or members. To import 
import * as ModuleElementUtils from "ojmodule-element-utils";

//Now you can access the methods as ModuleElementUtils.methodName and so on

JET In Typescript

A detailed description of working with JET elements and classes in your typescript project can be found at: JET Typescript Usage.

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. In addition to loading a view, the loadView() method also converts loaded data into an array of nodes - format accepted by oj-module.

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'} });

Methods

(static) .createConfig(options) → {Promise}

PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

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 any <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) → {Promise}

PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

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(options) → {Promise}

PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

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 any <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