Skip to content

Add item.chain getter #4

@nuxodin

Description

@nuxodin

Similar to path (which returns an array of keys), chain would return an array of the actual item instances from root to the current item.

get chain() {
    if (this.#parent == null) return [this];
    return [...this.#parent.chain, this];
}

Difference to path:

item.path   // ['users', '42', 'name']  – array of keys (strings)
item.chain  // [rootItem, usersItem, item42, nameItem]  – array of Item instances

Useful when you need to traverse or inspect the ancestor items themselves, not just their keys.

Naming alternatives

Before implementing, worth considering alternative names:

Name Notes
chain current proposal, known from method chaining / Promise chains
breadcrumbs very intuitive for "path from root to here", common in UI navigation
trace known from stack traces
lineage descriptive but uncommon in JS APIs
ancestors slightly misleading as it would also include the item itself

Leaning towards chain (consistent with existing ecosystem) or breadcrumbs (most intuitive semantically). Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions