Skip to content

Computed Values

Computed values (compute) are for derivations. Use them when you want to transform data without the semantic overhead of “success” or “failure” that Guards provide.

Computes take a name, a list of dependencies, and a transform function.

import { source, compute } from '@pulse-js/core';
const firstName = source('Alice');
const lastName = source('Smith');
const fullName = compute('full-name', [firstName, lastName], (first, last) => {
return `${first} ${last}`; // "Alice Smith"
});
  • Memoized: They only re-calculate when inputs change.
  • Pure: They should not have side effects.
  • Observable: You can subscribe to them or use them in Guards.
FeatureCompute (compute)Guard (guard)
PurposeData TransformationBusiness Logic / Validation
Return TypeAny ValueBoolean/Promise (mostly)
Has Status?NoYes (ok, fail, pending)
Has Reason?NoYes