dynamic-forms / Class

DerivationLookup

Decorators:@Injectable

Provides lazy-computed lookup maps for derivation entries.

Instead of pre-computing all lookup maps at collection time (which caused hidden mutation and bloated the DerivationCollection god object), this class computes maps lazily on first access and caches them.

Accessors

get byArrayPath

Map of array path to entries that derive array item values. Used for O(1) lookup when an array field changes.

Presentation
get byArrayPath(): Map<string, DerivationEntry[]>;
Type

Map<string, DerivationEntry[]>

get byDependency

Map of dependency field key to entries that depend on it. Used for efficient O(1) lookup when filtering by changed fields.

Presentation
get byDependency(): Map<string, DerivationEntry[]>;
Type

Map<string, DerivationEntry[]>

get byField

Map of field key to entries that target it. Since derivations are self-targeting, this maps field keys to their derivations. Used for quick lookup when processing derivations.

Presentation
get byField(): Map<string, DerivationEntry[]>;
Type

Map<string, DerivationEntry[]>

get entries

Current derivation entries (from signal). Auto-invalidates cache if entries reference changed.

Presentation
get entries(): DerivationEntry[];
Type

DerivationEntry[]

get wildcardEntries

Entries that have wildcard (*) dependency. These entries depend on all form values and must always be considered.

Presentation
get wildcardEntries(): DerivationEntry[];
Type

DerivationEntry[]

Methods

getDebouncedEntries()

Gets entries with trigger 'debounced' for a specific debounce period.

Presentation
getDebouncedEntries(debounceMs: number): DerivationEntry[];
Parameters
NameTypeDescription
debounceMs
number
Returns

getDebouncePeriods()

Gets all unique debounce periods that have entries.

Presentation
getDebouncePeriods(): number[];
Returns
number[]

getEntriesForChangedFields()

Gets entries that should be processed based on changed fields.

Handles nested path matching: if 'address' changed, entries depending on 'address.city' will also be included (parent change implies child changed).

Uses O(k) lookup via indexed maps for exact matches, plus O(d) scan for nested dependencies, where k = changed fields, d = unique dependencies.

Presentation
getEntriesForChangedFields(changedFields: Set<string>): DerivationEntry[];
Parameters
NameTypeDescription
changedFields
Set<string>
Returns

getOnChangeEntries()

Gets entries with trigger 'onChange' (or no trigger, which defaults to onChange).

Presentation
getOnChangeEntries(): DerivationEntry[];
Returns

invalidateCache()

Invalidates cached maps. Call this when entries change.

Presentation
invalidateCache(): void;
Returns
void

Example usage

const lookup = inject(DerivationLookup);

// Lazy-computed on first access
const entriesForQuantity = lookup.byDependency.get('quantity');
const onChangeEntries = lookup.getOnChangeEntries();