Skip to main content

Class: AbstractController

@ima/core.AbstractController

Basic implementation of the Controller interface, providing the default implementation of the most of the API.

Hierarchy

Constructors

constructor

new AbstractController()

Inherited from

Controller.constructor

Properties

_extensions

Protected _extensions: Map<Extension | IExtension, Extension>

Defined in

packages/core/src/controller/AbstractController.ts:12


_pageStateManager

Protected Optional _pageStateManager: PageStateManager

Defined in

packages/core/src/controller/AbstractController.ts:11


params

params: UnknownParameters = {}

The route parameters extracted from the current route. This field is set externally by IMA right before the init or the update method is called.

Defined in

packages/core/src/controller/AbstractController.ts:22


status

status: number = 200

The HTTP response code to send to the client.

Defined in

packages/core/src/controller/AbstractController.ts:16

Accessors

$extensions

Static get $extensions(): IExtension[]

Returns

IExtension[]

Defined in

packages/core/src/controller/AbstractController.ts:24

Methods

activate

activate(): void

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

Inherited from

Controller.activate

Defined in

packages/core/src/controller/Controller.ts:59


addExtension

addExtension(extension, extensionInstance?): void

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

Parameters

NameType
extensionExtension | IExtension
extensionInstance?Extension

Returns

void

Overrides

Controller.addExtension

Defined in

packages/core/src/controller/AbstractController.ts:78


beginStateTransaction

beginStateTransaction(): void

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

Defined in

packages/core/src/controller/AbstractController.ts:51


cancelStateTransaction

cancelStateTransaction(): void

Cancels ongoing state transaction. Uncommitted state changes are lost.

Returns

void

Overrides

Controller.cancelStateTransaction

Defined in

packages/core/src/controller/AbstractController.ts:69


commitStateTransaction

commitStateTransaction(): void

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

Returns

void

Overrides

Controller.commitStateTransaction

Defined in

packages/core/src/controller/AbstractController.ts:60


deactivate

deactivate(): void

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 activate method.

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

Returns

void

Inherited from

Controller.deactivate

Defined in

packages/core/src/controller/Controller.ts:74


destroy

destroy(): void

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 init method.

The controller should release all resources obtained in the 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

Inherited from

Controller.destroy

Defined in

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


getExtension

getExtension(extension): undefined | Extension

Inherit Doc

Parameters

NameType
extensionIExtension

Returns

undefined | Extension

Defined in

packages/core/src/controller/AbstractController.ts:97


getExtensions

getExtensions(): Extension[]

Returns the controller's extensions.

Returns

Extension[]

The extensions added to this controller.

Overrides

Controller.getExtensions

Defined in

packages/core/src/controller/AbstractController.ts:104


getHttpStatus

getHttpStatus(): number

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

Defined in

packages/core/src/controller/AbstractController.ts:132


getRouteParams

getRouteParams(): UnknownParameters

Returns the current route parameters.

Returns

UnknownParameters

The current route parameters.

Overrides

Controller.getRouteParams

Defined in

packages/core/src/controller/AbstractController.ts:118


getState

getState(): UnknownParameters

Returns the controller's current state.

Returns

UnknownParameters

The current state of this controller.

Overrides

Controller.getState

Defined in

packages/core/src/controller/AbstractController.ts:40


init

init(): void

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

Returns

void

Inherited from

Controller.init

Defined in

packages/core/src/controller/Controller.ts:28


load

load(): UnknownPromiseParameters | Promise<UnknownPromiseParameters>

Callback the controller uses to request the resources it needs to render its view. This method is invoked after the 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

UnknownPromiseParameters | Promise<UnknownPromiseParameters>

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.

Inherited from

Controller.load

Defined in

packages/core/src/controller/Controller.ts:113


setMetaParams

setMetaParams(loadedResources, metaManager, router, dictionary, settings): void

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

NameTypeDescription
loadedResourcesUnknownParametersA plain object representing a map of resource names to resources loaded by the load method. This is the same object as the one passed to the setState method.
metaManagerMetaManagerMeta attributes manager to configure.
routerRouterThe current application router.
dictionaryDictionaryThe current localization dictionary.
settingsUnknownParametersThe application settings for the current application environment.

Returns

void

Inherited from

Controller.setMetaParams

Defined in

packages/core/src/controller/Controller.ts:240


setPageStateManager

setPageStateManager(pageStateManager?): void

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

NameTypeDescription
pageStateManager?PageStateManagerThe current state manager to use.

Returns

void

Overrides

Controller.setPageStateManager

Defined in

packages/core/src/controller/AbstractController.ts:125


setRouteParams

setRouteParams(params?): void

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

Parameters

NameTypeDescription
paramsUnknownParametersThe current route parameters.

Returns

void

Overrides

Controller.setRouteParams

Defined in

packages/core/src/controller/AbstractController.ts:111


setState

setState(statePatch): void

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 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 load method.

Parameters

NameTypeDescription
statePatchUnknownParametersPatch of the controller's state to apply.

Returns

void

Overrides

Controller.setState

Defined in

packages/core/src/controller/AbstractController.ts:31


update

update(prevParams): UnknownPromiseParameters | Promise<UnknownPromiseParameters>

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 load method. The controller's state will only be patched by the returned object instead of replacing it completely.

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

Parameters

NameTypeDescription
prevParamsUnknownParametersPrevious route parameters.

Returns

UnknownPromiseParameters | Promise<UnknownPromiseParameters>

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.

Inherited from

Controller.update

Defined in

packages/core/src/controller/Controller.ts:139