Skip to content

Commit

Permalink
fix: make plugin loading idempotent, fixes #692
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Nov 17, 2020
1 parent 8808065 commit 754331b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion __tests__/map-set.js
Expand Up @@ -5,7 +5,8 @@ import {
original,
isDraft,
immerable,
enableAllPlugins
enableAllPlugins,
enableMapSet
} from "../src/immer"
import {each, shallowCopy, isEnumerable, DRAFT_STATE} from "../src/common"

Expand Down Expand Up @@ -280,5 +281,19 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
})
expect(result).toBe(set)
})

test("#692 - idempotent plugin loading", () => {
let mapType1
produce(new Map(), draft => {
mapType1 = draft.constructor
})

enableMapSet()
let mapType2
produce(new Map(), draft => {
mapType2 = draft.constructor
})
expect(mapType1).toBe(mapType2)
})
})
}
2 changes: 1 addition & 1 deletion src/utils/plugins.ts
Expand Up @@ -62,7 +62,7 @@ export function loadPlugin<K extends keyof Plugins>(
pluginKey: K,
implementation: Plugins[K]
): void {
plugins[pluginKey] = implementation
if (!plugins[pluginKey]) plugins[pluginKey] = implementation
}

/** ES5 Plugin */
Expand Down

0 comments on commit 754331b

Please sign in to comment.