Skip to content

Commit

Permalink
fix(type): export Options interface
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Jan 2, 2023
1 parent fc64ab8 commit eb9b324
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Overall, Mutative has a huge performance lead over Immer in [more performance te
| Non-global config |||
| Support IE browser |||

> Mutative draft functions don't allow return value (except for `void` or `Promise<void>`), but immer is allowed.
> Mutative draft functions don't allow return value (except for `void` or `Promise<void>`), but Immer is allowed.
Mutative has fewer bugs such as accidental draft escapes than Immer, [view details](https://github.com/unadlib/mutative/blob/main/test/immer-non-support.test.ts).

Expand Down Expand Up @@ -275,6 +275,7 @@ const state = create(baseState, (draft) => {
- `Immutable<T>`
- `Patches`
- `Patch`
- `Options<O, F>`

### Integration with React

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mutative",
"version": "0.2.1",
"version": "0.2.2",
"description": "A JavaScript library for efficient creation of immutable state",
"main": "dist/index.js",
"module": "dist/mutative.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export { unsafe } from './unsafe';
export { isDraft } from './utils/draft';

export { castDraft, castImmutable } from './utils/cast';
export type { Immutable, Draft, Patches, Patch } from './interface';
export type { Immutable, Draft, Patches, Patch, Options } from './interface';
28 changes: 28 additions & 0 deletions test/immer-non-support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,31 @@ test('immer failed case - escaped draft', () => {
}).not.toThrowError();
}
});

test('immer failed case - escaped draft about return value', () => {
{
setAutoFreeze(false);
const dataSet = [{}, {}, {}] as any;
const data = {
data: null,
a: {
b: 1,
c: 1,
},
};
const producer = produce((draft: any) => {
const a = draft.a;
dataSet[0] = a;
dataSet[1].a = { b: 1, c: [a] };
draft.a.b = 2;
draft.a.c = 2;
return {
...dataSet,
};
});

expect(() => {
JSON.stringify(producer(data));
}).toThrowError();
}
});

0 comments on commit eb9b324

Please sign in to comment.