mutative • Docs
mutative / 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.
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();
• _F extends boolean
= false
• _O extends PatchesOptions
= false
• options?: Options
<_O
, _F
>
Function
• T extends unknown
• F extends boolean
= _F
• O extends PatchesOptions
= _O
• R extends unknown
= void
• base: T
• mutate
• options?: Options
<O
, F
>
CreateResult
<T
, O
, F
, R
>
• T extends unknown
• F extends boolean
= _F
• O extends PatchesOptions
= _O
• R extends void
| Promise
<void
> = void
• base: T
• mutate
• options?: Options
<O
, F
>
CreateResult
<T
, O
, F
, R
>
• T extends unknown
• P extends any
[] = []
• F extends boolean
= _F
• O extends PatchesOptions
= _O
• R extends void
| Promise
<void
> = void
• mutate
• options?: Options
<O
, F
>
Function
• base: T
• ...args: P
CreateResult
<T
, O
, F
, R
>
• T extends unknown
• O extends PatchesOptions
= _O
• F extends boolean
= _F
• base: T
• options?: Options
<O
, F
>
[Draft
<T
>, () => Result
<T
, O
, F
>]