mutative • Docs
mutative / create
create(baseState, callback, options)
to create the next state
import { create } from '../index';
const baseState = { foo: { bar: 'str' }, arr: [] };
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);
create<
T
,F
,O
,R
>(base
,mutate
,options
?):CreateResult
<T
,O
,F
,R
>
create(baseState, callback, options)
to create the next state
import { create } from '../index';
const baseState = { foo: { bar: 'str' }, arr: [] };
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);
• T extends unknown
• F extends boolean
= false
• O extends PatchesOptions
= false
• R extends unknown
= void
• base: T
• mutate
• options?: Options
<O
, F
>
CreateResult
<T
, O
, F
, R
>
create<
T
,F
,O
,R
>(base
,mutate
,options
?):CreateResult
<T
,O
,F
,R
>
create(baseState, callback, options)
to create the next state
import { create } from '../index';
const baseState = { foo: { bar: 'str' }, arr: [] };
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);
• T extends unknown
• F extends boolean
= false
• O extends PatchesOptions
= false
• R extends void
| Promise
<void
> = void
• base: T
• mutate
• options?: Options
<O
, F
>
CreateResult
<T
, O
, F
, R
>
create<
T
,P
,F
,O
,R
>(mutate
,options
?): (base
, ...args
) =>CreateResult
<T
,O
,F
,R
>
create(baseState, callback, options)
to create the next state
import { create } from '../index';
const baseState = { foo: { bar: 'str' }, arr: [] };
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);
• T extends unknown
• P extends any
[] = []
• F extends boolean
= false
• O extends PatchesOptions
= false
• R extends void
| Promise
<void
> = void
• mutate
• options?: Options
<O
, F
>
Function
• base: T
• ...args: P
CreateResult
<T
, O
, F
, R
>
create<
T
,O
,F
>(base
,options
?): [Draft
<T
>, () =>Result
<T
,O
,F
>]
create(baseState, callback, options)
to create the next state
import { create } from '../index';
const baseState = { foo: { bar: 'str' }, arr: [] };
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);
• T extends unknown
• O extends PatchesOptions
= false
• F extends boolean
= false
• base: T
• options?: Options
<O
, F
>
[Draft
<T
>, () => Result
<T
, O
, F
>]