Function

withPreviousValue

@ng-forge/dynamic-forms

Wraps a Resource so that the previous resolved value is preserved while the resource is loading or reloading. This prevents UI flicker when params change and a new request is in-flight — the consumer sees the stale value with a loading/reloading status instead of undefined.

Uses Angular's resource.snapshot + resourceFromSnapshots composition pattern.

Signature

function withPreviousValue<
  T
>(input: Resource<T>): Resource<T>

Type Parameters

NameConstraintDefaultDescription
T---

Parameters

NameTypeDescription
inputResource<T>-

Returns

Resource<T>

Examples

const user = withPreviousValue(
  resource({ params: () => userId(), loader: ({ params }) => fetchUser(params) })
);
// user.value() keeps the old user data during loading transitions