A detailed description of working with JET elements and classes in your typescript project can be found at:
JET Typescript Usage.
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.
// 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
}
);