Skip to main content
Version: 2.2.0

Activator – durandal/activator

caution

The interface documentation for this module is incomplete. Declarations may be missing or invalid.

The activator module encapsulates all logic related to screen/component activation. An activator is essentially an asynchronous state machine that understands a particular state transition protocol. The protocol ensures that the following series of events always occur: canDeactivate (previous state), canActivate (new state), deactivate (previous state), activate (new state). Each of the can callbacks may return a boolean, affirmative value or promise for one of those. If either of the can functions yields a false result, then activation halts.

Variables​

defaults​

defaults: ActivatorSettings

The default settings used by activators.

Functions​

create​

create(initialActiveItem?, settings?: ActivatorSettings): Activator

Creates a new activator.

  • (param) initialActiveItem – The item which should be immediately activated upon creation of the ativator.
  • (param) settings – Per activator overrides of the default activator settings.
  • returns – The created activator.

isActivator​

isActivator(object?): boolean

Determines whether or not the provided object is an activator or not.

  • (param) object – Any object you wish to verify as an activator or not.
  • returns – True if the object is an activator; false otherwise.

Interfaces​

Activator​

interface Activator<T>
settings: DurandalActivatorSettings
The settings for this activator.
isActivating: KnockoutObservable<boolean>
An observable which indicates whether or not the activator is currently in the process of activating an instance.
canDeactivateItem(item: T, close: boolean): JQueryPromise<boolean>
Determines whether or not the specified item can be deactivated.
  • (param) item – The item to check.
  • (param) close – Whether or not to check if close is possible.
deactivateItem(item: T, close: boolean): JQueryPromise<boolean>
Deactivates the specified item.
  • (param) item – The item to deactivate.
  • (param) close – Whether or not to close the item.
canActivateItem(newItem: T, activationData?): JQueryPromise<boolean>
Determines whether or not the specified item can be activated.
  • (param) item – The item to check.
  • (param) activationData – Data associated with the activation.
activateItem(newItem: T, activationData?): JQueryPromise<boolean>
Activates the specified item.
  • (param) newItem – The item to activate.
  • (param) newActivationData – Data associated with the activation.
canActivate(): JQueryPromise<boolean>
Determines whether or not the activator, in its current state, can b activated.
activate(): JQueryPromise<boolean>
Activates the activator, in its current state.
canDeactivate(close: boolean): JQueryPromise<boolean>
Determines whether or not the activator, in its current state, can b deactivated.
deactivate(close: boolean): JQueryPromise<boolean>
Deactivates the activator, in its current state.
includeIn(includeIn): void
Adds canActivate, activate, canDeactivate and deactivate functions to the provided model which pass through to the corresponding functions on the activator.
forItems(items): DurandalActivator<T>
Sets up a collection representing a pool of objects which the activator will activate. See below for details. Activators without an item bool always close their values on deactivate. Activators with an items pool only deactivate, but do not close them.

ActivatorSettings​

closeOnDeactivate: boolean = true
The default value passed to an object's deactivate function as its close parameter.
affirmations: string[] = ['yes', 'ok', 'true']
Lower-cased words which represent a truthy value.
interpretResponse(value): boolean
Interprets the response of a canActivate or canDeactivate call using the known affirmative values in the affirmations array.
areSameItem(currentItem, newItem, currentActivationData, newActivationData): boolean
Determines whether or not the current item and the new item are the same.
beforeActivate(newItem)
Called immediately before the new item is activated.
afterDeactivate(oldItem, close: boolean, setter: Function): void
Called immediately after the old item is deactivated.
  • (param) oldItem – The previous item.
  • (param) close – Whether or not the previous item was closed.
  • (param) setter – The activate item setter function.