Register an item (and, recursively, its whole subtree) in its own root's id index, so getItemById can find
it. Call once a subtree's relationship to its parent is settled - see renderHtml, which is the one place
that happens for a freshly-attached subtree. Does nothing when item is not under a real root yet (or ever).
Repairs two ways an item can reach this point without the id createCoreItem is supposed to have already
stamped on it, rather than requiring every consumer to avoid either:
No id at all (typeof item.id !== 'number'): a raw plain config object merged directly onto an
already-rendered tree (si-funciona's mergeObjectsMutable, by reference, "as is", when the two sides'
shapes do not line up index-for-index - see updatePlayerStats.ts) never passed through createCoreItem at
all, so it has no id (or parentItem, or has map) whatsoever.
A collision (the id is already registered to a different item within this same root): a generic "build
one item, then replicate it N times" helper (si-funciona's buildArray, cloning rather than constructing
fresh - the shape treeloom-matrix's own buildMatrix uses for a grid's rows/columns/tiles) copies whatever id
the one template already carries into every copy right along with everything else, with no way for
treeloom to know that happened before registration.
Catching both here, at the one real choke point every attached item passes through, protects against these
patterns (and any other generic cloning or raw merging this codebase does not yet know about) without
needing every consumer to avoid them. A real reuse of someone else's id (rather than two different items
both starting unassigned) is not realistically distinguishable from the collision case, so the same repair
applies regardless of cause - the alternative (leaving it in place) silently breaks resolution for one of
the two items, which is worse than quietly handing the second one a fresh id.
Register an item (and, recursively, its whole subtree) in its own root's id index, so getItemById can find it. Call once a subtree's relationship to its parent is settled - see renderHtml, which is the one place that happens for a freshly-attached subtree. Does nothing when item is not under a real root yet (or ever).
Repairs two ways an item can reach this point without the id createCoreItem is supposed to have already stamped on it, rather than requiring every consumer to avoid either:
typeof item.id !== 'number'): a raw plain config object merged directly onto an already-rendered tree (si-funciona's mergeObjectsMutable, by reference, "as is", when the two sides' shapes do not line up index-for-index - see updatePlayerStats.ts) never passed through createCoreItem at all, so it has no id (or parentItem, or has map) whatsoever.Catching both here, at the one real choke point every attached item passes through, protects against these patterns (and any other generic cloning or raw merging this codebase does not yet know about) without needing every consumer to avoid them. A real reuse of someone else's id (rather than two different items both starting unassigned) is not realistically distinguishable from the collision case, so the same repair applies regardless of cause - the alternative (leaving it in place) silently breaks resolution for one of the two items, which is worse than quietly handing the second one a fresh id.