dynamic-forms / Function

applyDerivations

Applies all pending derivations from a collection.

This function processes derivations in order, evaluating conditions and computing values. It handles loop prevention through:

  1. Chain tracking (prevents same derivation from running twice in one cycle)
  2. Value equality checks (skips if target already has computed value)
  3. Max iteration limit (safety fallback)

Presentation

function applyDerivations(
  collection: DerivationCollection,
  context: DerivationApplicatorContext,
  changedFields?: Set<string> | undefined,
): DerivationProcessingResult;

Returns

DerivationProcessingResult -

Result of the derivation processing

Parameters

NameTypeDescription
collection
DerivationCollection

The collected derivation entries

context
DerivationApplicatorContext

Context for applying derivations

changedFields
Set<string> | undefined

Set of field keys that changed (for filtering)

Example usage

const result = applyDerivations(collection, {
  formValue: formValueSignal,
  rootForm: form(),
  derivationFunctions: customFnConfig?.derivations,
  logger: inject(DynamicFormLogger),
});

if (result.maxIterationsReached) {
  console.warn('Possible derivation loop detected');
}