Skip to content

Commit

Permalink
Revert enableMapSet
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Apr 5, 2023
1 parent aa0e5ee commit 6523d2e
Show file tree
Hide file tree
Showing 27 changed files with 490 additions and 342 deletions.
2 changes: 2 additions & 0 deletions __tests__/__prod_snapshots__/plugins.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`error when using Maps 1`] = `"[Immer] minified error nr: 0. Full error at: https://bit.ly/3cXEKWf"`;

exports[`error when using patches - 1 1`] = `"[Immer] minified error nr: 0. Full error at: https://bit.ly/3cXEKWf"`;

exports[`error when using patches - 2 1`] = `"[Immer] minified error nr: 0. Full error at: https://bit.ly/3cXEKWf"`;
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/plugins.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`error when using Maps 1`] = `"[Immer] The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and call \`enableMapSet()\` when initializing your application."`;

exports[`error when using patches - 1 1`] = `"[Immer] The plugin for 'Patches' has not been loaded into Immer. To enable the plugin, import and call \`enablePatches()\` when initializing your application."`;

exports[`error when using patches - 2 1`] = `"[Immer] The plugin for 'Patches' has not been loaded into Immer. To enable the plugin, import and call \`enablePatches()\` when initializing your application."`;
Expand Down
8 changes: 5 additions & 3 deletions __tests__/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import {
original,
isDraft,
immerable,
enablePatches
enablePatches,
enableMapSet
} from "../src/immer"
import {each, shallowCopy, DRAFT_STATE} from "../src/internal"
import deepFreeze from "deep-freeze"
import * as lodash from "lodash"

jest.setTimeout(1000)

enablePatches()
enableMapSet()

jest.setTimeout(1000)

const isProd = process.env.NODE_ENV === "production"

Expand Down
5 changes: 4 additions & 1 deletion __tests__/current.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import {
isDraft,
produce,
original,
freeze
freeze,
enableMapSet
} from "../src/immer"

enableMapSet()

runTests("proxy", true)

const isProd = process.env.NODE_ENV === "production"
Expand Down
10 changes: 9 additions & 1 deletion __tests__/empty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import {produce, immerable, applyPatches, enablePatches} from "../src/immer"
import {
produce,
produceWithPatches,
immerable,
enableMapSet,
enablePatches,
applyPatches
} from "../src/immer"
import {DRAFT_STATE, Patch} from "../src/internal"

enableMapSet()
enablePatches()

test("empty stub test", () => {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/flow/flow.js.flow
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// @flow
import {
produce,
enableMapSet,
setAutoFreeze,
produce as produce2,
applyPatches,
Patch,
original
} from "../../dist/index.js.flow"

enableMapSet()
setAutoFreeze(true)

// we really don't want this code to actually execute..
Expand Down
10 changes: 9 additions & 1 deletion __tests__/frozen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
"use strict"
import {produce, setUseProxies, setAutoFreeze, freeze} from "../src/immer"
import {
produce,
setUseProxies,
setAutoFreeze,
freeze,
enableMapSet
} from "../src/immer"

enableMapSet()

const {isFrozen} = Object

Expand Down
5 changes: 4 additions & 1 deletion __tests__/map-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
original,
isDraft,
immerable,
enablePatches
enablePatches,
enableMapSet
} from "../src/immer"
import {each, shallowCopy, isEnumerable, DRAFT_STATE} from "../src/utils/common"

enableMapSet()
enablePatches()

jest.setTimeout(1000)
Expand Down Expand Up @@ -283,6 +285,7 @@ function runBaseTest(name, autoFreeze, useListener) {
mapType1 = draft.constructor
})

enableMapSet()
let mapType2
produce(new Map(), draft => {
mapType2 = draft.constructor
Expand Down
4 changes: 3 additions & 1 deletion __tests__/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
isDraft,
immerable,
nothing,
enablePatches
enablePatches,
enableMapSet
} from "../src/immer"

enablePatches()
enableMapSet()

jest.setTimeout(1000)

Expand Down
6 changes: 6 additions & 0 deletions __tests__/plugins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {produce, produceWithPatches, applyPatches} from "../src/immer"

test("error when using Maps", () => {
expect(() => {
produce(new Map(), function() {})
}).toThrowErrorMatchingSnapshot()
})

test("error when using patches - 1", () => {
expect(() => {
produce(
Expand Down
2 changes: 2 additions & 0 deletions __tests__/produce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import {
Draft,
Immutable,
Immer,
enableMapSet,
enablePatches
} from "../src/immer"

enableMapSet()
enablePatches()

interface State {
Expand Down
6 changes: 4 additions & 2 deletions __tests__/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
applyPatches,
immerable,
produceWithPatches,
setAutoFreeze,
enablePatches
enableMapSet,
enablePatches,
setAutoFreeze
} from "../src/immer"

enableMapSet()
enablePatches()

describe("readme example", () => {
Expand Down
11 changes: 10 additions & 1 deletion __tests__/regressions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
"use strict"
import {Immer, nothing, original, isDraft, immerable} from "../src/immer"
import {
Immer,
nothing,
original,
isDraft,
immerable,
enableMapSet
} from "../src/immer"

enableMapSet()

runBaseTest("proxy (no freeze)", true, false)
runBaseTest("proxy (autofreeze)", true, true)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"build:flow": "cpx 'src/types/index.js.flow' dist -v",
"publish-docs": "cd website && GIT_USER=mweststrate USE_SSH=true yarn docusaurus deploy",
"start": "cd website && yarn start",
"test:size": "yarn build && yarn import-size --report . produce enablePatches",
"test:size": "yarn build && yarn import-size --report . produce enableMapSet enablePatches",
"test:sizequick": "tsdx build --name immer --format esm && yarn import-size . produce"
},
"husky": {
Expand Down
8 changes: 3 additions & 5 deletions src/core/immerClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import {
getCurrentScope,
NOTHING,
freeze,
current,
proxyMap,
proxySet
current
} from "../internal"

interface ProducersFns {
Expand Down Expand Up @@ -204,9 +202,9 @@ export function createProxy<T extends Objectish>(
): Drafted<T, ImmerState> {
// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft
const draft: Drafted = isMap(value)
? proxyMap(value, parent)
? getPlugin("MapSet").proxyMap_(value, parent)
: isSet(value)
? proxySet(value, parent)
? getPlugin("MapSet").proxySet_(value, parent)
: createProxyProxy(value, parent)

const scope = parent ? parent.scope_ : getCurrentScope()
Expand Down
Loading

0 comments on commit 6523d2e

Please sign in to comment.