Class: ModuleRouterAdapter

Oracle® JavaScript Extension Toolkit (JET)
9.2.0

F30740-01

Signature:

class ModuleRouterAdapter<D extends {[key: string]: any} = {[key: string]: any}, P extends {[key: string]: any} = {[key: string]: any}>

QuickNav

Fields

ModuleRouterAdapter

Version:
  • 9.2.0
Since:
  • 8.0.0
Module:
  • ojmodulerouter-adapter

Module usage

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

Javascript Import Format
define(['ojs/ojmodulerouter-adapter'], function(ModuleRouterAdapter) {
 // Application should call API on ModuleRouterAdapter 
})
Typescript Import Format
//This class is exported directly as module. To import it
import ModuleRouterAdapter= require("ojs/ojmodulerouter-adapter");

Generic Parameters
ParameterDescription
DDetail object for the router state
PParameters object for the router state

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

ModuleRouterAdapter utility class.

This class is designed to be an adapter between oj-module element and CoreRouter object. The properties defined on the class correspond to attributes on oj-module element. The koObservableConfig property created and updated by the class is based on the current state of the CoreRouter. The adapter also supports animation property, which is an implementation of ModuleElementAnimation interface that can be used for oj-module animation.

ModuleRouterAdapter reacts to changes of the beforeStateChange and currentState observable properties of CoreRouter. Upon a change to beforeStateChange, ModuleRouterAdapter will invoke the canExit() callback of the current view model if it's defined; the Promise returned by this callback is passed on to the CoreRouter to allow the pending state change to be canceled. Note that canExit() callback will be invoked on every beforeStateChange mutation regardless whether the module path is changed or view model parameters are changed.

Upon a change to the CoreRouter's currentState (i.e. a state change that was not canceled), ModuleRouterAdapter will load the requested view and view model and update its koObservableConfig property. View models may also optimize updates by implementing the parametersChanged() callback. If this callback is present, CoreRouter state changes that do not result in changes to the module path will be handled by invoking this callback on the already loaded view model with the new state parameter values.

When the view model is loaded by ModuleRouterAdapter, an instance of ViewModelParameters will be passed either to the model constructor or to the initialize method on the loaded model instance. See parameter passing contract in ModuleElementUtils.createConfig().


// define animation callback used to transition between views
var animationCallback = function (context) {
   return context.previousViewModel ? 'pushEnd' : 'fade';
};

// create a new instance of ModuleRouterAdapter
var adapter = new ModuleRouterAdapter(
   baseRouter,
   {
     viewPath: 'views/baserouter/',
     viewModelPath: 'viewModels/baserouter/',
     animationCallback: animationCallback
   }
);

Constructor

new ModuleRouterAdapter(router, options)

Parameters:
Name Type Argument Description
router CoreRouter.<D, P> The instance of the CoreRouter, that manages application navigation for a page or a section of the page.
options Object <optional>
Options object used for loading views and view models and configuring oj-module animation.
Properties
Name Type Argument Description
viewPath string <optional>
The path to the view, relative to the RequireJS baseURL. The text plugin will be used for loading the view. If the option is not provided the default path will be used - 'views/'.
viewModelPath string <optional>
The path to the model, relative to the RequireJS baseURL. If the option is not provided the default path wil be used - 'viewModels/'.
pathKey string <optional>
An optional key for retrieving module name from 'details' object on the router state. By default the adapter will use the 'path' field of the router state as the name for the module. However when 'path' does not represent the name of the module, the name can be retrieved from 'details' object on the router state using specified pathKey.
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.
animationCallback (animationContext: ModuleRouterAdapter.AnimationCallbackParameters) => ModuleAnimations.Animations | ModuleElementAnimation <optional>
An optional animation callback used to animate transitions between views.
The function will get a context object as a parameter. A return value should be a string containing an animation type supported by ModuleAnimations or an object that implements ModuleElementAnimation interface.

Fields

animation :oj.ModuleElementAnimation

An implementation of ModuleElementAnimation interface created by the ModuleRouterAdapter, which can be used as the animation property of the oj-module element. This property is created only when animationCallback property is defined for the ModuleRouterAdapter.

koObservableConfig :{view: Array.<Node>, viewModel: oj.ModuleViewModel}

The observable object created by the ModuleRouterAdapter, which can be used as the config property of the oj-module element.

Type Definitions

AnimationCallbackParameters

Properties:
Name Type Description
node Element An oj-module element used for hosting the views
previousViewModel any The instance of previous ViewModel
viewModel any The instance of the current ViewModel
previousState any Previous router state.
state any Current router state.

ViewModelParameters<D, P>

Properties:
Name Type Description
parentRouter CoreRouter.<D, P> The instance of the CoreRouter, that used by the ModuleRouterAdapter instance.
Deprecated:
Since Description
8.1.0 Use router property instead.
params P The value of CoreRouterState params property.
Deprecated:
Since Description
8.1.0 Use CoreRouter.CoreRouterState.params instead.
router CoreRouter.<D, P> The instance of the CoreRouter, that used by the ModuleRouterAdapter instance.
routerState CoreRouter.CoreRouterState<D, P> The current state of CoreRouter