File

libs/ngx-pfe/pfe-actions/pfe-actions.model.ts

Index

Properties

Properties

break
break: boolean
Type : boolean
Optional

If break is "true" and the action was executed (that means, no conditions or conditions returns true) The flow will be stopped and the next actions will not be executed

conditions
conditions: Conditions
Type : Conditions
Optional

A list of conditions under which the actions are executed

globalConfigId
globalConfigId: string
Type : string
Optional

Only valid on the navigation. Will spread the actions.

type
type: string
Type : string
Optional

A custom name unique for the action, for example, "UPDATE_STATE_VALUES" or "TRIGGER_SERVICE_ACTIVATORS"

import { PfeNestedActions } from './nested-actions/nested-actions.model';
import { BivariantCallbackFunction } from '../util/typescript/strict-function-types';
import { Conditions } from '../pfe-conditions/public-api';
import { PfeReloadPageActionConfig } from './reload-page/reload-page-action.model';
import { PfeResetStateActionConfig } from './reset-state/reset-state.model';
import { RewindHistoryActionConfig } from './rewind-history/rewind-history.model';
import { PfeTriggerServiceActivatorsActionConfig } from './trigger-service-activators/trigger-service-activators.model';
import { PfeUpdateStateOnBackendActionConfig } from './update-state-on-backend/update-state-on-backend.model';
import { PfeUpdateStateValuesActionConfig } from './update-state-values/update-state-values.model';

/**
 * These are the integrated default actions. Should be used as a basis for custom extensions in apps
 */
export type PfeActionConfig =
  | PfeTriggerServiceActivatorsActionConfig
  | PfeUpdateStateValuesActionConfig
  | PfeUpdateStateOnBackendActionConfig
  | RewindHistoryActionConfig
  | PfeReloadPageActionConfig
  | PfeResetStateActionConfig
  | PfeNestedActions<PfeActionConfig>;

/**
 * On the global actions the "type" is mandatory and we don't allow the "globalConfigId" key
 */
export interface PfeGlobalAction extends Pick<PfeBaseActionConfig, Exclude<keyof PfeBaseActionConfig, 'globalConfigId'>> {
  type: string;
}

export interface PfeBaseActionConfig {
  /**
   *  A custom name unique for the action, for example, "UPDATE_STATE_VALUES" or "TRIGGER_SERVICE_ACTIVATORS"
   */
  type?: string;

  /**
   * A list of conditions under which the actions are executed
   */
  conditions?: Conditions;

  /**
   * If break is "true" and the action was executed (that means, no conditions or conditions returns true)
   * The flow will be stopped and the next actions will not be executed
   */
  break?: boolean;

  /**
   * Only valid on the navigation.
   * Will spread the actions.
   */
  globalConfigId?: string;
}

export interface GlobalActions<ACTION = PfeActionConfig> {
  [id: string]: ACTION;
}

/**
 * Actions have to implement this function.
 *
 * An action can return a boolean result to indicate if further execution should be stopped.
 * For example, this applies to a navigation that triggers an action.
 * If no boolean is returned, a positive (true) response is assumed.
 *
 * This works in a similar fashion as the Angular route guards with the difference that actions are not executed in parallel.
 * But: The break flag in the action config has to be set to true, to prevent further actions from being executed.
 *
 * If an exception is thrown by this function, the execution of the actions is aborted.
 * The function itself is responsible to handle things like a redirection to an error page, etc...
 */
export type PfeActionFunction = BivariantCallbackFunction<(actionConfig: PfeBaseActionConfig) => Promise<void | boolean>>;

export interface ExecutionResult {
  wasExecuted: boolean;
  actionResult: boolean;
}

results matching ""

    No results matching ""