Interface BareField<Value, Plugin>

The bare field provides the core field functionality.

interface BareField<Value, Plugin> {
    children: null | Field<any, Plugin>[];
    initialValue: Value;
    isTransient: boolean;
    key: any;
    parentField: null | Field<any, Plugin>;
    rootField: Field<any, Plugin>;
    subscribers: {
        [eventType: string]: Subscriber<any, Plugin>[];
    };
    value: Value;
    valueAccessor: ValueAccessor;
    at<Key>(key, defaultValue?): Field<ValueAt<Value, Key>, Plugin>;
    on(eventType, subscriber): Unsubscribe;
    on(eventType, subscriber): Unsubscribe;
    propagate(): void;
    setTransientValue(value): void;
    setValue(value): void;
}

Type Parameters

  • Value = any

    The field value.

  • Plugin = any

    The plugin injected into the field.

Properties

children: null | Field<any, Plugin>[]

The array of child fields that were previously accessed, or null if there are no children.

initialValue: Value

The initial value of the field.

isTransient: boolean

true if the value was last updated using setTransientValue, or false otherwise.

key: any

The key in the parent value that corresponds to the value of this field, or null if there's no parent.

parentField: null | Field<any, Plugin>

The parent field, or null if this is the root field.

rootField: Field<any, Plugin>

The root field.

subscribers: {
    [eventType: string]: Subscriber<any, Plugin>[];
}

The map from an event type to an array of associated subscribers.

Type declaration

value: Value

The current value of the field.

valueAccessor: ValueAccessor

The accessor that reads values of child fields from Field.value the value of this field, and updates the value of this field when child value is changed.

Methods

  • Returns a child field that controls the value which is stored under the given key in the current value.

    Type Parameters

    • Key extends unknown

      The key in the value of this field.

    Parameters

    • key: Key

      The key in the value of this field.

    • Optional defaultValue: ValueAt<Value, Key>

      The default value used if the value at given key is undefined.

    Returns Field<ValueAt<Value, Key>, Plugin>

    The child field instance.

  • Subscribes to all events.

    Parameters

    • eventType: "*"

      The type of the event.

    • subscriber: Subscriber<any, Plugin>

      The subscriber that would be triggered.

    Returns Unsubscribe

    The callback to unsubscribe the subscriber.

  • Subscribes to the field value changes. Event.data contains the previous field value.

    Parameters

    • eventType: "change:value"

      The type of the event.

    • subscriber: Subscriber<any, Plugin>

      The subscriber that would be triggered.

    Returns Unsubscribe

    The callback to unsubscribe the subscriber.

  • If the current value is transient then the value of the parent field is notified about the change and this field is marked as non-transient. No-op if the current value is non-transient.

    Returns void

  • Updates the value of the field, notifies child fields about the change, and marks value as transient.

    Parameters

    • value: Value | ((prevValue) => Value)

      The value to set, or a callback that receives a previous value and returns a new one.

    Returns void

  • Updates the field value and notifies both ancestors and child fields about the change. If the field withholds a transient value then it becomes non-transient.

    Parameters

    • value: Value | ((prevValue) => Value)

      The value to set, or a callback that receives a previous value and returns a new one.

    Returns void