const $apply: <T>(
$apply: (t: T) => T,
$revise?: (t: T) => Update<T>,
) =>
| { $apply: (t: T) => T, $revise: (t: T) => Update<T> }
| { $revise?: never, $apply: (t: T) => T }
Apply a function to a value.
import { $apply } from "@use-gpu/state";
const value = {
hello: {text: 'world', bar: 2},
foo: 1,
};
const update = {
// Optional: provide a second callback to revise(...) custom updates
hello: {text: $apply(text => text + ' !!!', text => $set(text)) },
};
expect(patch(value, update)).toEqual({
hello: {text: 'world !!!', bar: 2},
foo: 1,
});
packages / state / src / patch.ts