createKeyedRegistry
projects/core/utils/registry.ts
Description#
Signal-based keyed registry with a destroy-safe unregister path.
Encodes the registration lifecycle contract every cngx registry must
honour, so the classic teardown race is unwritable: when Angular
recreates a keyed child, the successor's register can run BEFORE the
predecessor's DestroyRef teardown - an unguarded unregister(key)
would then evict the successor's live registration. Here unregister
demands the holder instance and only removes on identity match.
Collision semantics mirror CngxErrorRegistry: registering a different
value under a live key is silently absorbed (swap-is-noop) with a
dev-mode warning, never an in-place swap - downstream readers keep
observing the instance they resolved.
The registry is plain signals - create it as a field on the owning directive / service, no injection context required.