optimistic-kit
v0.0.1
Published
Generic immutable optimistic state primitives for plain data.
Maintainers
Readme
Optimistic Kit
Generic immutable optimistic state primitives for plain data.
Framework-free optimistic state primitives for plain application data. A
state keeps an authoritative confirmed value, a visible projected value,
and an ordered list of pending actions. Commit, rollback, and reconciliation
return new state objects.
import { createOptimisticState, stageOptimistic, rollbackOptimistic } from "optimistic-kit";
const reduce = (count: number, change: number) => count + change;
let state = createOptimisticState<number, number>(0);
state = stageOptimistic(state, { id: "add-1", action: 1 }, reduce);
state.value; // 1
state = rollbackOptimistic(state, "add-1", reduce, "Request failed");
state.value; // 0The reducer is supplied by the consuming domain; this package does not assume React, a server API, or a particular persistence layer.
Development
npm run build