Skip to main content
cngx-src documentation

CngxErrorRegistry

Injectablev0.1.0

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.

https://cngxjs.github.io/cngx/examples/#/common/interactive/error/registry/provider-and-reveal-features

Index#

Methods#

getAggregator(name: string)

Returns the named aggregator, or undefined when not registered.

@paramnamestring
getScope(name: string)

Returns the named scope, or undefined when not registered.

@paramnamestring
registerAggregator#void
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.

@paramnamestring
registerScope#void
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.

@paramnamestring
reset#void
reset(name: string)

Resets the named scope. Idempotent; no-op if name not registered.

@paramnamestring
resetAll#void

Resets every registered scope.

reveal#void
reveal(name: string)

Reveals the named scope. Idempotent; no-op if name not registered.

@paramnamestring
revealAll#void

Reveals every registered scope.

unregisterAggregator#void
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.

@paramnamestring
unregisterScope#void
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.

@paramnamestring