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
| Name | Constraint | Default | Description |
|---|---|---|---|
T | - | - | - |
Parameters
| Name | Type | Description |
|---|---|---|
input | Resource<T> | - |
Returns
Resource<T>
Examples
const user = withPreviousValue(
resource({ params: () => userId(), loader: ({ params }) => fetchUser(params) })
);
// user.value() keeps the old user data during loading transitionspackages/dynamic-forms/src/lib/utils/resource-composition/with-previous-value.ts:21