diff --git a/README.md b/README.md index 25775ba6..e8182818 100644 --- a/README.md +++ b/README.md @@ -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`), but immer is allowed. +> Mutative draft functions don't allow return value (except for `void` or `Promise`), 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). @@ -275,6 +275,7 @@ const state = create(baseState, (draft) => { - `Immutable` - `Patches` - `Patch` +- `Options` ### Integration with React diff --git a/package.json b/package.json index 19b9f7d1..0ee20632 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 6007d554..2889aaed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/test/immer-non-support.test.ts b/test/immer-non-support.test.ts index bd1131fc..61813ddf 100644 --- a/test/immer-non-support.test.ts +++ b/test/immer-non-support.test.ts @@ -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(); + } +});