turbodombuilder - v0.9.66
    Preparing search index...

    Class TurboObserver<DataType, ComponentType, DataKeyType>

    TurboObserver

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

    The key type used at each level of the path.

    Type Parameters

    • DataType = any

      The type of data handled by the observer.

    • ComponentType extends object = any

      The instance type created/managed by the observer.

    • DataKeyType extends KeyType = KeyType

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _isInitialized: boolean = false
    onAdded: Delegate<
        (
            data: DataType,
            self: TurboObserver<DataType, ComponentType, DataKeyType>,
            ...keys: DataKeyType[],
        ) => void | ComponentType,
    > = ...

    Delegate called when a change is reported at a key path for which no component instance exists yet. Handlers may return a newly-created component instance, which will be stored and passed to subsequent onUpdated calls.

    onUpdated: Delegate<
        (
            data: DataType,
            instance: ComponentType,
            self: TurboObserver<DataType, ComponentType, DataKeyType>,
            ...keys: DataKeyType[],
        ) => void,
    > = ...

    Delegate called when a change is reported at a key path that already has an associated instance.

    onDeleted: Delegate<
        (
            data: DataType,
            instance: ComponentType,
            self: TurboObserver<DataType, ComponentType, DataKeyType>,
            ...keys: DataKeyType[],
        ) => void,
    > = ...

    Delegate called when a key path is reported as deleted.

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

    Delegate fired once when the observer is initialized. Useful for initial population.

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

    Delegate fired when the observer is destroyed.

    nestedMap: TurboNestedMapNode<DataKeyType, any> = ...

    Accessors

    • get isInitialized(): boolean

      Returns boolean

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

    • get entries(): [KeyType, ValueType][]

      Returns [KeyType, ValueType][]

      All leaf [key, value] pairs in the nested map, sorted alphabetically by key.

    • get keys(): KeyType[]

      Returns KeyType[]

      All leaf keys in the nested map, sorted alphabetically.

    • get values(): ValueType[]

      Returns ValueType[]

      All leaf values in the nested map, sorted alphabetically by key.

    • get paths(): KeyType[][]

      Returns KeyType[][]

      All leaf key paths in the map.

    • get size(): number

      Returns number

      Number of all leaf entries in the nested map.

    Methods

    • Function

      remove

      Parameters

      Returns void

      Remove the instance at the given key path from the map and call instance.remove() if available.

    • Function

      detach

      Parameters

      Returns void

      Remove the instance at the given key path from the map without calling instance.remove(), detaching it from the observer.

    • Function

      initialize

      Returns void

      Initialization method that fires onInitialize. No-op if already initialized.

    • Function

      clear

      Parameters

      • OptionalremoveFromDom: boolean = true

        Whether to call instance.remove() on each managed instance.

      Returns void

      Remove all managed instances, reset the observer to an uninitialized state, and optionally call instance.remove() on each instance.

    • Function

      destroy

      Parameters

      • OptionalremoveFromDom: boolean = true

        Whether to call instance.remove() on each managed instance.

      Returns void

      Remove all managed instances, reset the observer to an uninitialized state, optionally call instance.remove() on each instance, and fire onDestroy.

    • Function

      keyChanged

      Parameters

      • keys: DataKeyType[]

        The key path that changed.

      • value: DataType

        The new value at that path.

      • Optionaldeleted: boolean = false

        Whether the entry was deleted.

      Returns void

      Notify the observer of a change at the given key path. Fires onDeleted if deleted is true and an instance exists, onAdded if no instance exists yet (storing the returned instance if any), and onUpdated otherwise.

    • Function

      get

      Parameters

      • ...keys: DataKeyType[]

        Ordered path from outermost to innermost key.

      Returns ComponentType

      The stored value, or undefined if not found.

      Retrieve the value at the given key path.

    • Function

      getFlat

      Parameters

      • flatKey: string | number

        A flat key produced by flattenKey.

      Returns ComponentType

      The stored value, or undefined if not found.

      Retrieve the value at the given flat key.

    • Function

      getKey

      Parameters

      Returns DataKeyType[]

      The key path, or undefined if not found.

      Find the key path of the first occurrence of the given value.

    • Function

      getFlatKey

      Parameters

      Returns string | number

      The flat key, or undefined if not found.

      Return the flat key of the first occurrence of the given value.

    • Function

      set

      Parameters

      Returns void

      Store a value at the given key path. Intermediate nodes are created automatically.

    • Function

      setFlat

      Parameters

      Returns void

      Store a value at the given flat key.

    • Function

      has

      Parameters

      • ...keys: DataKeyType[]

        Ordered path from outermost to innermost key.

      Returns boolean

      Check whether an entry exists at the given key path.

    • Function

      hasFlat

      Parameters

      • flatKey: string | number

        A flat key produced by flattenKey.

      Returns boolean

      Check whether an entry exists at the given flat key.

    • Function

      hasValue

      Parameters

      Returns boolean

      Check whether the given value exists anywhere in the map.

    • Function

      removeValue

      Parameters

      Returns void

      Remove the first occurrence of the given value.

    • Function

      removeValues

      Parameters

      Returns void

      Remove all occurrences of the given value.

    • Function

      getKeysAt

      Parameters

      Returns DataKeyType[]

      Return all leaf keys under the given path, sorted alphabetically. Pass no keys to get all leaf keys in the map.

    • Function

      getValuesAt

      Parameters

      Returns ComponentType[]

      Return all leaf values under the given path, sorted alphabetically by key. Pass no keys to get all leaf values in the map.

    • Function

      getPathsAt

      Parameters

      Returns DataKeyType[][]

      Return all leaf key paths under the given path. Pass no keys to get all leaf paths in the map.

    • Function

      getSizeAt

      Parameters

      Returns number

      Return the number of leaf entries under the given path. Pass no keys to get the number of all leaf entries.

    • Function

      flattenKey

      Parameters

      Returns string | number

      The flat key, or undefined if the path is invalid.

      Serialize a key path into a single flat key.

      • Fully numeric paths produce a numeric global leaf index.
      • All other paths produce a "k0|k1|k2|..." string.
    • Function

      scopeKey

      Parameters

      • flatKey: string | number

        The flat key to convert.

      Returns DataKeyType[]

      The key path, or undefined if conversion fails.

      Convert a flat key back into a key path. Reverses flattenKey.

      • A string "k0|k1|k2" becomes [k0, k1, k2].
      • A numeric global leaf index becomes the corresponding numeric path.
    • Parameters

      • key: any

      Returns string | number