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?
Similar to
path(which returns an array of keys),chainwould return an array of the actual item instances from root to the current item.Difference to
path:Useful when you need to traverse or inspect the ancestor items themselves, not just their keys.
Naming alternatives
Before implementing, worth considering alternative names:
chainbreadcrumbstracelineageancestorsLeaning towards
chain(consistent with existing ecosystem) orbreadcrumbs(most intuitive semantically). Thoughts?