Provides the storage and sequencing of managed position validators. Each validator added may be a bespoke function or a ValidatorData object containing an id, validator, and weight attributes; validator is the only required attribute.

The id attribute can be anything that creates a unique ID for the validator; recommended strings or numbers. This allows validators to be removed by ID easily.

The weight attribute is a number between 0 and 1 inclusive that allows validators to be added in a predictable order which is especially handy if they are manipulated at runtime. A lower weighted validator always runs before a higher weighted validator. If no weight is specified the default of '1' is assigned and it is appended to the end of the validators list.

This class forms the public API which is accessible from the .validators getter in the main TJSPosition instance.

const position = new TJSPosition(<TJSPositionData>);
position.validators.add(...);
position.validators.clear();
position.validators.length;
position.validators.remove(...);
position.validators.removeBy(...);
position.validators.removeById(...);

Constructors

Accessors

  • get enabled(): boolean
  • Returns boolean

    Returns the enabled state.s

  • set enabled(arg): void
  • Parameters

    • arg: boolean

    Returns void

  • get length(): number
  • Returns number

    Returns the length of the validators array.

Methods

  • Provides an iterator for validators.

    Returns Generator<{
        id?: any;
        subscribe?: Function;
        validator: ValidatorFn;
        weight?: number;
    }, void, unknown>

    Yields

  • Returns void

  • Remove validators by the provided callback. The callback takes 3 parameters: id, validator, and weight. Any truthy value returned will remove that validator.

    Parameters

    • callback: ((arg0, arg1, arg2) => boolean)

      Callback function to evaluate each validator entry.

        • (arg0, arg1, arg2): boolean
        • Parameters

          Returns boolean

    Returns void

  • Parameters

    • Rest ...ids: any[]

    Returns void