Skip to content

Commit 754331b

Browse files
committedNov 17, 2020
fix: make plugin loading idempotent, fixes #692
1 parent 8808065 commit 754331b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎__tests__/map-set.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
original,
66
isDraft,
77
immerable,
8-
enableAllPlugins
8+
enableAllPlugins,
9+
enableMapSet
910
} from "../src/immer"
1011
import {each, shallowCopy, isEnumerable, DRAFT_STATE} from "../src/common"
1112

@@ -280,5 +281,19 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
280281
})
281282
expect(result).toBe(set)
282283
})
284+
285+
test("#692 - idempotent plugin loading", () => {
286+
let mapType1
287+
produce(new Map(), draft => {
288+
mapType1 = draft.constructor
289+
})
290+
291+
enableMapSet()
292+
let mapType2
293+
produce(new Map(), draft => {
294+
mapType2 = draft.constructor
295+
})
296+
expect(mapType1).toBe(mapType2)
297+
})
283298
})
284299
}

‎src/utils/plugins.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function loadPlugin<K extends keyof Plugins>(
6262
pluginKey: K,
6363
implementation: Plugins[K]
6464
): void {
65-
plugins[pluginKey] = implementation
65+
if (!plugins[pluginKey]) plugins[pluginKey] = implementation
6666
}
6767

6868
/** ES5 Plugin */

0 commit comments

Comments
 (0)
Please sign in to comment.