Class: ModuleElementUtils

Oracle® JavaScript Extension Toolkit (JET)
5.0.0

E90577-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:
  • 5.0.0
Since:
  • 5.0.0
Module:
  • ojmodule-element-utils

Utility methods for oj-module element

ModuleElementUtils is a helper object that provides convenience methods for creating views and view models 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.

Usage :


//create oj-module config as an observable and initialize it with empty values
self.moduleConfig = ko.observable({'view':[],'viewModel':null});

//create view and view model, mutate configuration object to update oj-module content
var masterPromise = Promise.all([
  moduleElementUtils.createView({'viewPath':'views/ojModule-simple/page.html'}),
  moduleElementUtils.createViewModel({'viewModelPath':'viewModels/ojModule-simple/page'})
 ]);
 masterPromise.then(
   function(values){
     self.moduleConfig({'view':values[0],'viewModel':values[1]});
   },
   function(reason){}
 );

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

Methods

(static) createView(options) → {Promise}

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 function <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.
Returns:
A promise that resolves into an array of DOM nodes
Type
Promise
Example

Get promise for the view

var viewPromise = moduleElementUtils.createView({'viewPath':'views/ojModule-simple/page.html'});

(static) createViewModel(options) → {Promise}

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 function <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.
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
Example

Get promise for the model

var modelPromise = moduleElementUtils.createViewModel({'viewModelPath':'viewModels/ojModule-simple/pageModel'});