turbodombuilder - v0.9.48
    Preparing search index...

    Class TurboDataBlock<DataType, KeyType, IdType, ComponentType, DataEntryType>

    TurboDataBlock

    Lightweight wrapper around a plain JS container (object, Array or Map) that exposes a consistent API for reads/writes, signals, TurboObservers and host callbacks. Use this when you want change notifications and host integration around a simple data block.

    Type Parameters

    • DataType = any

      The type of the data held in the block.

    • KeyType extends string | number | symbol = any

      The type of the data's keys.

    • IdType extends string | number | symbol = any

      The type of the data's ID.

    • ComponentType extends object = any

      For observers. The type of instances that react to changes in the block.

    • DataEntryType = any

      For observers. The type of the data associated with each observer instance.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    id: IdType
    isInitialized: boolean = false
    changeObservers: TurboWeakSet<
        TurboObserver<DataEntryType, ComponentType, KeyType, string>,
    > = ...
    onKeyChanged: Delegate<(key: KeyType, value: any) => void> = ...

    Delegate fired when the value changes at a certain key/index.

    observerConstructor: new (...args: any[]) => TurboObserver = ...

    The default class of observers to instantiate.

    Type Declaration

    Accessors

    • get data(): DataType

      Returns DataType

      The data held by this block. Setting it will clear attached observers and re-initialize the block.

    • set data(data: DataType): void

      Parameters

      Returns void

    enabledCallbacks: boolean

    Whether callbacks are enabled.

    • get keys(): KeyType[]

      Returns KeyType[]

      Array of all keys currently present in the block.

    • get values(): any[]

      Returns any[]

      The block's values in an array (in the order implied by keys).

    • get size(): number

      Returns number

      Number of entries in the block.

    Methods

    • Function

      get

      Parameters

      • key: KeyType

        The key/index to read.

      Returns any

      • The stored value, or undefined if not present.

      Retrieve the value stored at the given key.

    • Function

      set

      Parameters

      • key: KeyType

        The key/index to write.

      • value: unknown

        The value to set.

      Returns void

      Set a value at the provided key and notify observers/signals if the value changed.

    • Function

      add

      Parameters

      • value: unknown

        The value to insert.

      • Optionalkey: KeyType

        Optional numeric index to insert at. If omitted, the value is pushed.

      Returns void | KeyType

      • The index where the value was inserted (for arrays), or void for non-arrays.

      Append or insert a value into an array-backed data block. If the block is not an array, the call forwards to set.

    • Function

      has

      Parameters

      • key: KeyType

        The key/index to check.

      Returns boolean

      • True, if present.

      Check whether the given key exists in the block.

    • Function

      delete

      Parameters

      • key: KeyType

        The key/index to remove.

      Returns void

      Remove the entry at the given key/index and notify observers.

    • Function

      initialize

      Returns void

      Fire change notifications for every existing key, initializing the block.

    • Function

      clear

      Parameters

      • OptionalclearData: boolean = true

        If true, also clears the stored data. Otherwise, only resets observers/state.

      Returns void

      Clear the block and its observers.

    • Function

      toJSON

      Returns object

      • Plain JSON-serializable representation.

      Convert the block into a plain object suitable for JSON serialization.

    • Function

      unlink

      Returns void

      Detach any previously-linked host.

    • Function

      makeSignal

      Type Parameters

      • Type = any

        The type of the signal's value.

      Parameters

      • key: KeyType

        The key for which to create the signal.

      Returns SignalBox<Type>

      • The created or cached signal.

      Create (or return an existing) reactive SignalBox for the given key. The returned signal reads from get and writes via set.

    • Function

      getSignal

      Parameters

      • key: KeyType

        The key whose signal to retrieve.

      Returns any

      • The signal or undefined if none was created.

      Retrieve an existing SignalBox for the given key if present.

    • Function

      makeAllSignals

      Returns void

      Create signals for every key currently present in the block.

    • Protected Function

      keyChanged

      Parameters

      • key: KeyType

        The key that changed.

      • Optionalvalue: unknown = ...

        The new value (or undefined for deletions).

      • Optionaldeleted: boolean = false

        Whether the key was removed.

      Returns void

      Internal hook called whenever a key is added/updated/deleted.