turbodombuilder - v0.9.66
    Preparing search index...

    Class TurboNodeList<Type>

    TurboNodeList

    A composable, Set-like collection for managing nodes. Supports individual nodes, live DOM collections (HTMLCollection or NodeListOf), and nested TurboNodeList instances as sub-lists. Changes to sub-lists and live DOM collections propagate automatically on iteration.

    Type Parameters

    • Type extends object = object

      The type of the nodes held in the list.

    Index

    Constructors

    • Type Parameters

      • Type extends object = object

        The type of the nodes held in the list.

      Parameters

      • Optional...values: (Type | NodeListType<Type>)[]

        Optional initial value(s) to populate the list with.

      Returns TurboNodeList<Type>

    Properties

    onChanged: Delegate<(entry: Type, state: "added" | "removed") => void> = ...

    Delegate fired whenever an entry is added to or removed from the list, including entries from nested TurboNodeLists, HTMLCollections, and NodeListOf instances.

    Accessors

    • set observeDomLists(value: boolean): void

      Parameters

      • value: boolean

      Returns void

      Whether to observe added HTMLCollections and NodeListOf instances for DOM mutations, automatically firing onChanged when nodes are added or removed from the DOM.

    • get list(): Set<Type>

      Returns Set<Type>

      A Set snapshot of all entries in this list, without duplicates.

    • set list(value: NodeListType<Type>): void

      Parameters

      Returns void

    • get array(): Type[]

      Returns Type[]

      An array snapshot of all entries in this list, without duplicates.

    • get size(): number

      Returns number

      The number of resolved unique entries in this list. For the number of slots, see slotCount.

    • get slotCount(): number

      Returns number

      The number of slots in this list. Individual entries, HTMLCollections, NodeListOf instances, and nested TurboNodeLists each count as one slot, regardless of how many entries they contain. For the number of resolved entries, see size.

    Methods

    • Protected Function

      isTurboNodeList

      Parameters

      • entry: any

        The value to check.

      Returns entry is TurboNodeList<Type>

      Whether the value is a TurboNodeList.

      Type guard — returns true if the given value is a TurboNodeList.

    • Protected Function

      isDomList

      Parameters

      • entry: any

        The value to check.

      Returns entry is HTMLCollection | NodeListOf<Type & Node>

      Whether the value is a DOM list.

      Type guard — returns true if the given value is an HTMLCollection or NodeListOf.

    • Protected Function

      isSet

      Parameters

      • entry: any

        The value to check.

      Returns entry is Set<Type> | Type[]

      Whether the value is a Set or array.

      Type guard — returns true if the given value is a Set or an array.

    • Protected Function

      isEntry

      Parameters

      • entry: any

        The value to check.

      Returns entry is Type

      Whether the value is an individual entry.

      Type guard — returns true if the given value is an individual node entry (i.e. not a TurboNodeList, DOM list, Set, array, or WeakRef).

    • Returns IterableIterator<Type>

      Iterates over all resolved unique entries in slot order, skipping ignored and duplicate entries.

    • Function

      resolveSlot

      Parameters

      Returns IterableIterator<Type>

      Resolves a slot WeakRef into its constituent entries. Yields all entries from sub-lists and DOM lists, or the single entry for individual node slots. Yields nothing if the referent has been garbage collected.

    • Parameters

      • callback: (value: Type, set: this) => void
      • OptionalthisArg: any

      Returns this

    • Function

      add

      Parameters

      Returns this

      Itself, allowing for method chaining.

      Adds one or more entries to the end of the list. Entries may be individual nodes, arrays, Sets, HTMLCollections, NodeListOf instances, or nested TurboNodeLists.

    • Function

      addAt

      Parameters

      • index: number

        The resolved entry index to insert at.

      • ...entries: (Type | NodeListType<Type>)[]

        The entries to add.

      Returns this

      Itself, allowing for method chaining.

      Adds one or more entries at the given resolved size index. The index refers to the position among resolved unique entries, not slots. Arrays and Sets are expanded inline.

    • Function

      addAtSlot

      Parameters

      • index: number

        The slot index to insert at.

      • ...entries: (Type | NodeListType<Type>)[]

        The entries to add.

      Returns this

      Itself, allowing for method chaining.

      Adds one or more entries at the given slot index. Subsequent entries are inserted consecutively after the previous one. Arrays and Sets are expanded inline, each item occupying the next slot index.

    • Function

      remove

      Parameters

      Returns this

      Itself, allowing for method chaining.

      Removes one or more entries from the list. Entries may be individual nodes, arrays, Sets, HTMLCollections, NodeListOf instances, or nested TurboNodeLists.

    • Function

      removeAtSlot

      Parameters

      • index: number

        The slot index to start removing from.

      • Optionalcount: number = 1

        The number of consecutive slots to remove.

      Returns this

      Itself, allowing for method chaining.

      Removes one or more slots starting at the given slot index. Each slot removed may correspond to an individual entry, a DOM list, or a nested TurboNodeList.

    • Function

      move

      Parameters

      • entry: Type

        The entry to move.

      • index: number

        The resolved entry index to move the entry to.

      Returns this

      Itself, allowing for method chaining.

      Moves an existing entry to the given resolved size index. If the entry is a member of a nested TurboNodeList, it is moved within that sub-list. If it belongs to a DOM list, it is repositioned in the DOM accordingly.

    • Function

      moveToSlot

      Parameters

      • entry: Type

        The entry to move.

      • index: number

        The slot index to move the entry to.

      Returns this

      Itself, allowing for method chaining.

      Moves an existing entry to the given slot index.

    • Function

      has

      Parameters

      Returns boolean

      Whether the entry or entries are present in the list.

      Checks whether the given entry or entries are present in the list.

      • For TurboNodeLists and DOM lists, checks if they belong to this list.
      • For arrays and Sets, returns true only if every item is present.
    • Function

      clear

      Returns this

      Itself, allowing for method chaining.

      Clears all entries from the list, firing onChanged for every resolved entry.

    • Function

      addEntry

      Parameters

      • entry: Type | NodeListType<Type>

        The entry to add.

      • Optionalindex: number

        The slot index to insert at. Defaults to the end of the slot array.

      Returns number

      The next available slot index after this insertion, for consecutive chaining.

      Core insertion method. Inserts a single entry, DOM list, sub-list, or expands an array/Set inline. Skips already-present entries and duplicate slots. Registers sub-list handlers and DOM observers as needed.

    • Function

      removeEntry

      Parameters

      Returns void

      Core removal method. Removes a single entry, DOM list, sub-list, or expands an array/Set inline. Marks removed individual entries in ignoredMap. Disconnects observers and unregisters sub-list handlers as needed.

    • Function

      insertOrRemoveSlot

      Parameters

      • slot: NodeListSlot<Type>

        The slot value to insert or remove.

      • state: "added" | "removed"

        Whether to insert or remove the slot.

      • Optionalindex: number

        Slot index for insertion. Ignored on removal.

      Returns number

      The next available slot index after the operation, for consecutive chaining.

      Low-level slot mutation. On "added", clamps the index and splices a new WeakRef into slots. On "removed", finds the slot by identity and splices it out. Fires onChanged for all resolved entries of the slot.

    • Function

      attachObserver

      Parameters

      Returns void

      Attaches a MutationObserver to the parent of the first node in the given DOM list, firing onChanged when nodes matching the list are added to or removed from the DOM. Does nothing if an observer is already attached for this list, or if no parent node is found.

    • Parameters

      • sizeIndex: number

      Returns number

    • Protected Function

      findContainingSlot

      Parameters

      • entry: Type

        The entry to locate.

      Returns NodeListSlot<Type>

      The containing slot, or undefined if not found.

      Finds the slot that directly contains or resolves to the given entry. Returns the slot itself if the entry is a direct slot, the nested TurboNodeList that contains it, or the DOM list that contains it.