CngxErrorRegistry
projects/common/interactive/error-registry/error-registry.ts
Import#
import { CngxErrorRegistry } from '@cngx/common/interactive'
Description#
Programmatic registry for named error scopes and aggregators.
Provides a lookup surface so consumers (route guards, HTTP interceptors,
test harnesses) can inspect or drive form-error state without traversing
the DOM. Directives with cngxErrorScopeName / cngxErrorAggregatorName
inputs auto-register here when the registry is provided in the host
environment via provideErrorRegistry.
Not providedIn: 'root' - consumers opt in by including
provideErrorRegistry() in their bootstrapApplication providers. When
the registry is absent, the directives skip registration and keep their
pure DOM behaviour.
Index#
Methods#
CngxErrorAggregatorContract | undefinedgetAggregator(name: string)Returns the named aggregator, or undefined when not registered.
registerAggregator(name: string, aggregator: CngxErrorAggregatorContract)Registers the named aggregator. Idempotent for the same
(name, aggregator) pair.
Swap-is-noop (intentional): see registerScope for the full
rationale. Re-registering a different aggregator instance under an
existing name is silently absorbed by mapKeySetEqual; downstream
readers stay attached to the originally registered contract. Use
unregisterAggregator(name) then registerAggregator(name, newAgg)
for a true swap.
registerScope(name: string, scope: CngxErrorScopeContract)Registers the named scope. Idempotent for the same (name, scope)
pair.
Swap-is-noop (intentional): registering a different scope
instance under an existing name is silently absorbed. The internal
scopesState signal carries equal: mapKeySetEqual, which short-
circuits when the key set is unchanged. Downstream readers (and any
subsequent getScope(name) call) keep observing the originally
registered instance.
To perform a true swap, call unregisterScope(name) first, then
registerScope(name, newScope) - the unregister cycle changes the
key set, the equal fn emits, and the new instance becomes the live
value.
unregisterAggregator(name: string, aggregator: CngxErrorAggregatorContract)Removes the named aggregator, but only when aggregator is the stored
instance. No-op if absent or if a different instance holds the name - a
late destroy of a swap-absorbed duplicate must not evict the live winner.
unregisterScope(name: string, scope: CngxErrorScopeContract)Removes the named scope, but only when scope is the stored instance.
No-op if absent or if a different instance holds the name - a late
destroy of a swap-absorbed duplicate must not evict the live winner.