Skip to content
Myr

fix: add more traps for Maps and Sets

Before adoption: this commit came in with the history the project adopted, so no landing records it.

These traps ensure the underlying state is never touched by the user.

authored by Andrey Goncharov · committed by Alec Larson · parent 6255a58 · Browse files · 1 file+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−0 removed

  • other:+27 added−0 removed

1 file+27 added−0 removed

modified:src/proxy.js+27 added
398 unmodified lines
399 : Reflect.get(state, prop, receiver)400 },401 ownKeys(state) {402 return Reflect.ownKeys(source(state))403 },404 set(state, ...args) {405 return Reflect.set(source(state), ...args)406 },407 has(state, ...args) {408 return Reflect.has(source(state), ...args)409 },410 deleteProperty(state, ...args) {411 return Reflect.deleteProperty(source(state), ...args)412 },413 defineProperty(state, ...args) {414 return Reflect.defineProperty(source(state), ...args)415 },416 getOwnPropertyDescriptor(state, ...args) {417 return Reflect.getOwnPropertyDescriptor(source(state), ...args)418 },419 preventExtensions(state) {420 return Reflect.preventExtensions(source(state))421 },422 isExtensible(state) {423 return Reflect.isExtensible(source(state))424 },425 getPrototypeOf(state) {426 return Reflect.getPrototypeOf(source(state))427 },428 setPrototypeOf(state) {429 throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft") // prettier-ignore430 }431 }432}