mutative • Docs
mutative / apply
apply<
T,F>(state,patches,applyOptions?):T|Fextendstrue?Immutable<T> :T
apply(state, patches) to apply patches to state
import { create, apply } from '../index';
const baseState = { foo: { bar: 'str' }, arr: [] };
const [state, patches] = create(
baseState,
(draft) => {
draft.foo.bar = 'str2';
},
{ enablePatches: true }
);
expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
expect(patches).toEqual([{ op: 'replace', path: ['foo', 'bar'], value: 'str2' }]);
expect(state).toEqual(apply(baseState, patches));• T extends object
• F extends boolean = false
• state: T
• patches: Patches
• applyOptions?: Pick<Options<boolean, F>, "mark" | "strict" | "enableAutoFreeze">
T | F extends true ? Immutable<T> : T