Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 1.23 KB

apply.md

File metadata and controls

51 lines (32 loc) · 1.23 KB

mutativeDocs


mutative / apply

Function: apply()

apply<T, F>(state, patches, applyOptions?): T | F extends true ? Immutable<T> : T

apply(state, patches) to apply patches to state

Example

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));

Type Parameters

T extends object

F extends boolean = false

Parameters

state: T

patches: Patches

applyOptions?: Pick<Options<boolean, F>, "mark" | "strict" | "enableAutoFreeze">

Returns

T | F extends true ? Immutable<T> : T

Defined in

apply.ts:26