turbodombuilder - v0.9.48
    Preparing search index...

    Class TurboObserver<DataType, ComponentType, KeyType, BlockKeyType>

    TurboObserver

    Generic observer that keeps a set of component instances organized by block key and item key. Useful to maintain UI components or other per-entry objects synchronized with a data source (e.g. a TurboDataBlock or a TurboModel).

    Type Parameters

    • DataType = any

      The type of data handled by the observer.

    • ComponentType extends object = any

      The instance type created/managed by the observer.

    • KeyType extends string | number | symbol = string

      The per-item key type.

    • BlockKeyType extends string | number = string

      The block-grouping key type.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _isInitialized: boolean = false
    onAdded: Delegate<
        (
            data: DataType,
            id: KeyType,
            self: TurboObserver<DataType, ComponentType, KeyType, BlockKeyType>,
            blockKey?: BlockKeyType,
        ) => void | ComponentType,
    > = ...

    Delegate called when an item appears for which no component instance exists. Handlers may return a newly-created component instance which will be stored and then receive subsequent onUpdated calls.

    onUpdated: Delegate<
        (
            data: DataType,
            instance: ComponentType,
            id: KeyType,
            self: TurboObserver<DataType, ComponentType, KeyType, BlockKeyType>,
            blockKey?: BlockKeyType,
        ) => void,
    > = ...

    Delegate called when an item already has an associated instance and its data changes.

    onDeleted: Delegate<
        (
            data: DataType,
            instance: ComponentType,
            id: KeyType,
            self: TurboObserver<DataType, ComponentType, KeyType, BlockKeyType>,
            blockKey?: BlockKeyType,
        ) => void,
    > = ...

    Delegate called when an item is removed.

    onInitialize: Delegate<
        (
            self: TurboObserver<DataType, ComponentType, KeyType, BlockKeyType>,
        ) => void,
    > = ...

    Delegate fired when the observer is initialized. Useful to perform initial population steps.

    onDestroy: Delegate<
        (
            self: TurboObserver<DataType, ComponentType, KeyType, BlockKeyType>,
        ) => void,
    > = ...

    Delegate fired when the observer is destroyed.

    Accessors

    • get isInitialized(): boolean

      Returns boolean

      Whether the observer has been initialized (i.e. initialize called).

    • get defaultBlockKey(): BlockKeyType
      Protected

      Returns BlockKeyType

      Default block key used when none is supplied. It returns the first blockKey if present, otherwise returns the sentinel "__default__".

    Methods

    • Function

      removeKey

      Parameters

      • key: KeyType

        The key to remove.

      • OptionalblockKey: BlockKeyType = ...

        Block grouping key.

      • OptionalremoveFromDOM: boolean = true

        Whether to call instance.remove() when available.

      Returns void

      Remove the instance associated with key inside blockKey.

    • Function

      remove

      Parameters

      • instance: ComponentType

        The instance to remove.

      • OptionalremoveFromDOM: boolean = true

        Whether to call instance.remove() when available.

      Returns void

      Remove a given instance.

    • Function

      initialize

      Returns void

      Invoke onInitialize and mark the observer as initialized.

    • Function

      clear

      Returns void

      Remove and destroy all managed instances and reset internal state.

    • Function

      destroy

      Returns void

      Clear then fire onDestroy.

    • Function

      keyChanged

      Parameters

      • key: KeyType

        The changed item key.

      • value: DataType

        The new value for the item.

      • Optionaldeleted: boolean = false

        Whether the item was removed.

      • OptionalblockKey: BlockKeyType = ...

        Block grouping key.

      Returns void

      Function to notify the observer of a change at a certain key.

    • Function

      getFlatKey

      Parameters

      Returns string | number

      • Flattened key, or undefined when value not found.

      Return the first flatKey (global index or flattened string key) for the provided value.

    • Function

      getFromFlatKey

      Parameters

      • flatKey: string | number

        Global index or flattened string key (produced by flattenKey).

      Returns ComponentType

      • The value, or undefined if not found.

      Get the value at the given flatKey.

    • Function

      getKeysForBlock

      Parameters

      Returns KeyType[]

      • Array of keys.

      Return the keys for a block alphabetically sorted (if compatible).

    • Function

      getAllKeys

      Returns KeyType[]

      • Flattened list of all keys.

      Return all keys from all blocks. Blocks are visited in alphabetical order of their blockKey (if compatible).

    • Function

      getAllValues

      Returns ComponentType[]

      • Flattened list of all values.

      Return all values from all blocks. Blocks are visited in alphabetical order of their blockKey (if compatible).

    • Function

      hasKey

      Parameters

      Returns boolean

      Whether a value exists.

      Check whether a value exists at the given key inside blockKey.

    • Function

      hasBlock

      Parameters

      Returns boolean

      Whether a block exists.

      Check whether a block exists at blockKey.

    • Function

      getBlockSize

      Parameters

      Returns number

      The size of the block.

      Get the number of entries inside the target block.

    • Function

      flattenKey

      Parameters

      Returns string | number

      • The flattened key.

      Produce a stable, serialized representation of (key, blockKey). For numeric block keys the function returns a numeric global index; otherwise it returns a "blockKey|key" string.