variable / @typed/async-data

optimistic

Adds an optimistic value above an existing AsyncData history.

Package version
1.0.0-beta.7
Category
Optimistic transitions
Since
1.0.0

Import

import { optimistic } from "@typed/async-data";

Signatures

export declare const optimistic: <A, E>(previous: AsyncData<A, E>, value: A) => Optimistic<A, E>;

Why

Keeping previous makes rollback and reconciliation explicit rather than mutating or discarding earlier state.

Ownership and lifetime

This pure function acquires no resources; the wrapper retains both supplied values.

Examples

import { optimistic, success } from "@typed/async-data"
const state = optimistic(success("saved"), "saving")

Source