Interface ValidatedBox<V, T>

Similar to Box, except the value can optionally be validated and transformed by that same validator.

interface ValidatedBox<V, T> {
    valid: boolean;
    validValue: T;
    value: V;
    setValue(value: V, group?: unknown): boolean;
    unwatch(callback: ObservableCallback<V>): this;
    validate(value: V): ValidationResult<T>;
    watch(callback: ObservableCallback<V>, callNow?: boolean, group?: unknown): this;
}

Type Parameters

Hierarchy (view full)

Implemented by

Properties

valid: boolean

If true, then the current value is valid.

validValue: T

The last valid value, post-transformation. If there was never a valid value, undefined is returned.

value: V

The current value.

When the value is set via this setter, the class implementing this interface should notify the observable with no group (undefined). Note that this is just a suggestion, not a strict requirement.

Methods

  • Sets Box#value. Does nothing if the value is already the one specified.

    Parameters

    • value: V
    • Optionalgroup: unknown

      The observable group that this change belongs to. undefined by default.

    Returns boolean

    Returns true if the value was changed, false if not

  • Register a callback to this observable. When the value is changed, the callback will be called.

    Parameters

    • callback: ObservableCallback<V>
    • OptionalcallNow: boolean

      If true, the callback will be called once immediately after it's registered. False by default

    • Optionalgroup: unknown

      The group to use when calling immediately. Only used if callNow is true, and is undefined by default

    Returns this