Skip to content

Latest commit

 

History

History
144 lines (79 loc) · 3.09 KB

makeCreator.md

File metadata and controls

144 lines (79 loc) · 3.09 KB

mutativeDocs


mutative / makeCreator

Function: makeCreator()

makeCreator<_F, _O>(options?): <T, F, O, R>(base, mutate, options?) => CreateResult<T, O, F, R><T, F, O, R>(base, mutate, options?) => CreateResult<T, O, F, R><T, P, F, O, R>(mutate, options?) => (base, ...args) => CreateResult<T, O, F, R><T, O, F>(base, options?) => [Draft<T>, () => Result<T, O, F>]

makeCreator(options) to make a creator function.

Example

import { makeCreator } from '../index';

const baseState = { foo: { bar: 'str' }, arr: [] };
const create = makeCreator({ enableAutoFreeze: true });
const state = create(
  baseState,
  (draft) => {
    draft.foo.bar = 'str2';
  },
);

expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
expect(state).not.toBe(baseState);
expect(state.foo).not.toBe(baseState.foo);
expect(state.arr).toBe(baseState.arr);
expect(Object.isFrozen(state)).toBeTruthy();

Type Parameters

_F extends boolean = false

_O extends PatchesOptions = false

Parameters

options?: Options<_O, _F>

Returns

Function

Type Parameters

T extends unknown

F extends boolean = _F

O extends PatchesOptions = _O

R extends unknown = void

Parameters

base: T

mutate

options?: Options<O, F>

Returns

CreateResult<T, O, F, R>

Type Parameters

T extends unknown

F extends boolean = _F

O extends PatchesOptions = _O

R extends void | Promise<void> = void

Parameters

base: T

mutate

options?: Options<O, F>

Returns

CreateResult<T, O, F, R>

Type Parameters

T extends unknown

P extends any[] = []

F extends boolean = _F

O extends PatchesOptions = _O

R extends void | Promise<void> = void

Parameters

mutate

options?: Options<O, F>

Returns

Function

Parameters

base: T

• ...args: P

Returns

CreateResult<T, O, F, R>

Type Parameters

T extends unknown

O extends PatchesOptions = _O

F extends boolean = _F

Parameters

base: T

options?: Options<O, F>

Returns

[Draft<T>, () => Result<T, O, F>]

Defined in

makeCreator.ts:87