Skip to main content

Class: ControllerDecorator<S, R, SS>

Defined in: packages/core/src/controller/ControllerDecorator.ts:18

Decorator for page controllers. The decorator manages references to the meta attributes manager and other utilities so these can be easily provided to the decorated page controller when needed.

Extends

Type Parameters

S extends PageState = {}

R extends RouteParams = {}

SS extends S = S

Indexable

[key: string | number | symbol]: any

Constructors

new ControllerDecorator()

new ControllerDecorator<S, R, SS>(controller, metaManager, router, dictionary, settings): ControllerDecorator<R, SS>

Defined in: packages/core/src/controller/ControllerDecorator.ts:54

Initializes the controller decorator.

Parameters

controller

Controller<S, R, SS>

The controller being decorated.

metaManager

MetaManager

The meta page attributes manager.

router

Router

The application router.

dictionary

Dictionary

Localization phrases dictionary.

settings

Settings

Application settings for the current application environment.

Returns

ControllerDecorator<R, SS>

Overrides

Controller.constructor

Properties

_controller

protected _controller: Controller<S, R, SS>

Defined in: packages/core/src/controller/ControllerDecorator.ts:26

The controller being decorated.


_dictionary

protected _dictionary: Dictionary

Defined in: packages/core/src/controller/ControllerDecorator.ts:38

Localization phrases dictionary.


_metaManager

protected _metaManager: MetaManager

Defined in: packages/core/src/controller/ControllerDecorator.ts:30

The meta page attributes manager.


_router

protected _router: Router

Defined in: packages/core/src/controller/ControllerDecorator.ts:34

The application router.


_settings

protected _settings: Settings

Defined in: packages/core/src/controller/ControllerDecorator.ts:42

Application settings for the current application environment.


$dependencies

static $dependencies: Dependencies

Defined in: packages/core/src/controller/Controller.ts:44

Inherited from

Controller.$dependencies


$extensions?

static optional $extensions: Dependencies<Extension>

Defined in: packages/core/src/controller/Controller.ts:45

Inherited from

Controller.$extensions


$name?

static optional $name: string

Defined in: packages/core/src/controller/Controller.ts:43

Inherited from

Controller.$name

Methods

activate()

activate(): void | Promise<void>

Defined in: packages/core/src/controller/ControllerDecorator.ts:87

Callback for activating the controller in the UI. This is the last method invoked during controller initialization, called after all the promises returned from the Controller#load method have been resolved and the controller has configured the meta manager.

The controller may register any React and DOM event listeners in this method. The controller may start receiving event bus event after this method completes.

Returns

void | Promise<void>

Overrides

Controller.activate


addExtension()

addExtension(extension, extensionInstance?): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:150

Adds the provided extension to this controller. All extensions should be added to the controller before the Controller#init method is invoked.

Parameters

extension

keyof OCAliasMap | Constructor<Extension<any, any, any>> | AbstractConstructor<Extension<any, any, any>> | Extension<PageState, RouteParams, PageState>

extensionInstance?

Extension<PageState, RouteParams, PageState>

Returns

void

Overrides

Controller.addExtension


beginStateTransaction()

beginStateTransaction(): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:129

Starts queueing state patches off the controller state. While the transaction is active every setState call has no effect on the current state.

Note that call to getState after the transaction has begun will return state as it was before the transaction.

Returns

void

Overrides

Controller.beginStateTransaction


cancelStateTransaction()

cancelStateTransaction(): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:143

Cancels ongoing state transaction. Uncommitted state changes are lost.

Returns

void

Overrides

Controller.cancelStateTransaction


commitStateTransaction()

commitStateTransaction(): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:136

Applies queued state patches to the controller state. All patches are squashed and applied with one setState call.

Returns

void

Overrides

Controller.commitStateTransaction


deactivate()

deactivate(): void | Promise<void>

Defined in: packages/core/src/controller/ControllerDecorator.ts:94

Callback for deactivating the controller in the UI. This is the first method invoked during controller deinitialization. This usually happens when the user navigates to a different URL.

This method is the lifecycle counterpart of the Controller#activate method.

The controller should deregister listeners registered and release all resources obtained in the Controller#activate method.

Returns

void | Promise<void>

Overrides

Controller.deactivate


destroy()

destroy(): void | Promise<void>

Defined in: packages/core/src/controller/ControllerDecorator.ts:80

Finalization callback, called when the controller is being discarded by the application. This usually happens when the user navigates to a different URL.

This method is the lifecycle counterpart of the Controller#init method.

The controller should release all resources obtained in the Controller#init method. The controller must release any resources that might not be released automatically when the controller's instance is destroyed by the garbage collector.

Returns

void | Promise<void>

Overrides

Controller.destroy


getExtension()

getExtension(extension): undefined | Extension<PageState, RouteParams, PageState>

Defined in: packages/core/src/controller/ControllerDecorator.ts:164

Returns extension instance defined by it's class constructor from controller's extension intance map.

Parameters

extension

typeof Extension

Returns

undefined | Extension<PageState, RouteParams, PageState>

Overrides

Controller.getExtension


getExtensions()

getExtensions(): Extension[]

Defined in: packages/core/src/controller/ControllerDecorator.ts:173

Returns the controller's extensions.

Returns

Extension[]

The extensions added to this controller.

Overrides

Controller.getExtensions


getHttpStatus()

getHttpStatus(): number

Defined in: packages/core/src/controller/ControllerDecorator.ts:214

Returns the HTTP status code to send to the client, should the controller be used at the server-side.

Returns

number

The HTTP status code to send to the client.

Overrides

Controller.getHttpStatus


getMetaManager()

getMetaManager(): MetaManager

Defined in: packages/core/src/controller/ControllerDecorator.ts:225

Returns the meta attributes manager configured by the decorated controller.

Returns

MetaManager

The Meta attributes manager configured by the decorated controller.


getRouteParams()

getRouteParams(): R

Defined in: packages/core/src/controller/ControllerDecorator.ts:200

Returns the current route parameters.

Returns

R

The current route parameters.

Overrides

Controller.getRouteParams


getState()

getState(): SS

Defined in: packages/core/src/controller/ControllerDecorator.ts:122

Returns the controller's current state.

Returns

SS

The current state of this controller.

Overrides

Controller.getState


init()

init(): void | Promise<void>

Defined in: packages/core/src/controller/ControllerDecorator.ts:73

Callback for initializing the controller after the route parameters have been set on this controller.

Returns

void | Promise<void>

Overrides

Controller.init


load()

load(): S | Promise<S>

Defined in: packages/core/src/controller/ControllerDecorator.ts:101

Callback the controller uses to request the resources it needs to render its view. This method is invoked after the Controller#init method.

The controller should request all resources it needs in this method, and represent each resource request as a promise that will resolve once the resource is ready for use (these can be data fetched over HTTP(S), database connections, etc).

The method must return a plain flat object. The field names of the object identify the resources being fetched and prepared, each value must be either the resource (e.g. view configuration or a value retrieved synchronously) or a Promise that will resolve to the resource.

The IMA will use the object to set the state of the controller.

If at the server side, the IMA will wait for all the promises to resolve, replaces the promises with the resolved values and sets the resulting object as the controller's state.

If at the client side, the IMA will first set the controller's state to an object containing only the fields of the returned object that were not promises. IMA will then update the controller's state every time a promise of the returned object resolves. IMA will update the state by adding the resolved resource to the controller's state.

Any returned promise that gets rejected will redirect the application to the error page. The error page that will be used depends on the status code of the error.

Returns

S | Promise<S>

A map object of promises resolved when all resources the controller requires are ready. The resolved values will be pushed to the controller's state.

Overrides

Controller.load


setMetaParams()

setMetaParams(loadedResources): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:180

Callback used to configure the meta attribute manager. The method is called after the the controller's state has been patched with the all loaded resources and the view has been rendered.

Parameters

loadedResources

Intersection<Partial<Pick<SS, Matching<SS, Promise<any>>>>, Required<Pick<SS, NonMatching<SS, Promise<any>>>>>

A plain object representing a map of resource names to resources loaded by the Controller#load method. This is the same object as the one passed to the Controller#setState method.

Returns

void

Overrides

Controller.setMetaParams


setPageStateManager()

setPageStateManager(pageStateManager?): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:207

Sets the page state manager. The page state manager manages the controller's state. The state manager can be set to null if this controller loses the right to modify the state of the current page (e.g. the user has navigated to a different route using a different controller).

Parameters

pageStateManager?

PageStateManager<SS>

The current state manager to use.

Returns

void

Overrides

Controller.setPageStateManager


setRouteParams()

setRouteParams(params): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:193

Sets the current route parameters. This method is invoked before the Controller#init method.

Parameters

params

R = ...

The current route parameters.

Returns

void

Overrides

Controller.setRouteParams


setState()

setState<K>(statePatch): void

Defined in: packages/core/src/controller/ControllerDecorator.ts:115

Patches the state of this controller using the provided object by copying the provided patch object fields to the controller's state object.

You can use this method to modify the state partially or add new fields to the state object.

Note that the state is not patched recursively but by replacing the values of the top-level fields of the state object.

Once the promises returned by the Controller#load method are resolved, this method is called with the an object containing the resolved values. The field names of the passed object will match the field names in the object returned from the Controller#load method.

Type Parameters

K extends string | number | symbol

Parameters

statePatch

Patch of the controller's state to apply.

null | S | Pick<S, K>

Returns

void

Overrides

Controller.setState


update()

update(prevParams): S | Promise<S>

Defined in: packages/core/src/controller/ControllerDecorator.ts:108

Callback for updating the controller after a route update. This method is invoked if the current route has the onlyUpdate flag set to true and the current controller and view match those used by the previously active route, or, the onlyUpdate option of the current route is a callback and returned true.

The method must return an object with the same semantics as the result of the Controller#load method. The controller's state will only be patched by the returned object instead of replacing it completely.

The other controller lifecycle callbacks (Controller#init, Controller#load, Controller#activate, Controller#deactivate, Controller#deinit) are not call in case this method is used.

Parameters

prevParams

R = ...

Previous route parameters.

Returns

S | Promise<S>

A map object of promises resolved when all resources the controller requires are ready. The resolved values will be pushed to the controller's state.

Overrides

Controller.update