From 3fcc5e3ad67d166d37ffa6de5b525b63c96042b1 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Wed, 2 Mar 2022 14:45:56 +0800 Subject: [PATCH 1/3] fix: compatibility with ses --- src/plugins/mapset.ts | 417 +++++++++++++++++++++++++----------------- 1 file changed, 246 insertions(+), 171 deletions(-) diff --git a/src/plugins/mapset.ts b/src/plugins/mapset.ts index 17dc5ddb..8031f522 100644 --- a/src/plugins/mapset.ts +++ b/src/plugins/mapset.ts @@ -37,7 +37,9 @@ export function enableMapSet() { function __extends(d: any, b: any): any { extendStatics(d, b) function __(this: any): any { - this.constructor = d + Object.defineProperty(this, "constructor", { + value: d + }) } d.prototype = // @ts-ignore @@ -68,128 +70,168 @@ export function enableMapSet() { Object.defineProperty(p, "size", { get: function() { return latest(this[DRAFT_STATE]).size - } + }, // enumerable: false, - // configurable: true + configurable: true }) - p.has = function(key: any): boolean { - return latest(this[DRAFT_STATE]).has(key) - } - - p.set = function(key: any, value: any) { - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - if (!latest(state).has(key) || latest(state).get(key) !== value) { - prepareMapCopy(state) - markChanged(state) - state.assigned_!.set(key, true) - state.copy_!.set(key, value) - state.assigned_!.set(key, true) + Object.defineProperty(p, "has", { + configurable: true, + writable: true, + value: function(key: any): boolean { + return latest(this[DRAFT_STATE]).has(key) } - return this - } + }) - p.delete = function(key: any): boolean { - if (!this.has(key)) { - return false + Object.defineProperty(p, "set", { + configurable: true, + writable: true, + value: function(key: any, value: any) { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) + if (!latest(state).has(key) || latest(state).get(key) !== value) { + prepareMapCopy(state) + markChanged(state) + state.assigned_!.set(key, true) + state.copy_!.set(key, value) + state.assigned_!.set(key, true) + } + return this } + }) - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareMapCopy(state) - markChanged(state) - if (state.base_.has(key)) { - state.assigned_!.set(key, false) - } else { - state.assigned_!.delete(key) - } - state.copy_!.delete(key) - return true - } + Object.defineProperty(p, "delete", { + configurable: true, + writable: true, + value: function(key: any): boolean { + if (!this.has(key)) { + return false + } - p.clear = function() { - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - if (latest(state).size) { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) prepareMapCopy(state) markChanged(state) - state.assigned_ = new Map() - each(state.base_, key => { + if (state.base_.has(key)) { state.assigned_!.set(key, false) - }) - state.copy_!.clear() + } else { + state.assigned_!.delete(key) + } + state.copy_!.delete(key) + return true } - } + }) - p.forEach = function( - cb: (value: any, key: any, self: any) => void, - thisArg?: any - ) { - const state: MapState = this[DRAFT_STATE] - latest(state).forEach((_value: any, key: any, _map: any) => { - cb.call(thisArg, this.get(key), key, this) - }) - } + Object.defineProperty(p, "clear", { + configurable: true, + writable: true, + value: function() { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareMapCopy(state) + markChanged(state) + state.assigned_ = new Map() + each(state.base_, key => { + state.assigned_!.set(key, false) + }) + state.copy_!.clear() + } + } + }) - p.get = function(key: any): any { - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - const value = latest(state).get(key) - if (state.finalized_ || !isDraftable(value)) { - return value + Object.defineProperty(p, "forEach", { + configurable: true, + writable: true, + value: function( + cb: (value: any, key: any, self: any) => void, + thisArg?: any + ) { + const state: MapState = this[DRAFT_STATE] + latest(state).forEach((_value: any, key: any, _map: any) => { + cb.call(thisArg, this.get(key), key, this) + }) } - if (value !== state.base_.get(key)) { - return value // either already drafted or reassigned + }) + + Object.defineProperty(p, "get", { + configurable: true, + writable: true, + value: function(key: any): any { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) + const value = latest(state).get(key) + if (state.finalized_ || !isDraftable(value)) { + return value + } + if (value !== state.base_.get(key)) { + return value // either already drafted or reassigned + } + // despite what it looks, this creates a draft only once, see above condition + const draft = createProxy(state.scope_.immer_, value, state) + prepareMapCopy(state) + state.copy_!.set(key, draft) + return draft } - // despite what it looks, this creates a draft only once, see above condition - const draft = createProxy(state.scope_.immer_, value, state) - prepareMapCopy(state) - state.copy_!.set(key, draft) - return draft - } + }) - p.keys = function(): IterableIterator { - return latest(this[DRAFT_STATE]).keys() - } + Object.defineProperty(p, "keys", { + configurable: true, + writable: true, + value: function(): IterableIterator { + return latest(this[DRAFT_STATE]).keys() + } + }) - p.values = function(): IterableIterator { - const iterator = this.keys() - return { - [iteratorSymbol]: () => this.values(), - next: () => { - const r = iterator.next() - /* istanbul ignore next */ - if (r.done) return r - const value = this.get(r.value) - return { - done: false, - value + Object.defineProperty(p, "values", { + configurable: true, + writable: true, + value: function(): IterableIterator { + const iterator = this.keys() + return { + [iteratorSymbol]: () => this.values(), + next: () => { + const r = iterator.next() + /* istanbul ignore next */ + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value + } } - } - } as any - } + } as any + } + }) - p.entries = function(): IterableIterator<[any, any]> { - const iterator = this.keys() - return { - [iteratorSymbol]: () => this.entries(), - next: () => { - const r = iterator.next() - /* istanbul ignore next */ - if (r.done) return r - const value = this.get(r.value) - return { - done: false, - value: [r.value, value] + Object.defineProperty(p, "entries", { + configurable: true, + writable: true, + value: function(): IterableIterator<[any, any]> { + const iterator = this.keys() + return { + [iteratorSymbol]: () => this.entries(), + next: () => { + const r = iterator.next() + /* istanbul ignore next */ + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value: [r.value, value] + } } - } - } as any - } + } as any + } + }) - p[iteratorSymbol] = function() { - return this.entries() - } + Object.defineProperty(p, iteratorSymbol, { + configurable: true, + writable: true, + value: function() { + return this.entries() + } + }) return DraftMap })(Map) @@ -234,87 +276,120 @@ export function enableMapSet() { // enumerable: true, }) - p.has = function(value: any): boolean { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - // bit of trickery here, to be able to recognize both the value, and the draft of its value - if (!state.copy_) { - return state.base_.has(value) + Object.defineProperty(p, "has", { + configurable: true, + writable: true, + value: function(value: any): boolean { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + // bit of trickery here, to be able to recognize both the value, and the draft of its value + if (!state.copy_) { + return state.base_.has(value) + } + if (state.copy_.has(value)) return true + if ( + state.drafts_.has(value) && + state.copy_.has(state.drafts_.get(value)) + ) + return true + return false } - if (state.copy_.has(value)) return true - if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) - return true - return false - } + }) + Object.defineProperty(p, "add", { + configurable: true, + writable: true, + value: function(value: any): any { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + if (!this.has(value)) { + prepareSetCopy(state) + markChanged(state) + state.copy_!.add(value) + } + return this + } + }) + Object.defineProperty(p, "delete", { + configurable: true, + writable: true, + value: function(value: any): any { + if (!this.has(value)) { + return false + } - p.add = function(value: any): any { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - if (!this.has(value)) { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) prepareSetCopy(state) markChanged(state) - state.copy_!.add(value) + return ( + state.copy_!.delete(value) || + (state.drafts_.has(value) + ? state.copy_!.delete(state.drafts_.get(value)) + : /* istanbul ignore next */ false) + ) } - return this - } - - p.delete = function(value: any): any { - if (!this.has(value)) { - return false + }) + Object.defineProperty(p, "clear", { + configurable: true, + writable: true, + value: function() { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareSetCopy(state) + markChanged(state) + state.copy_!.clear() + } } - - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareSetCopy(state) - markChanged(state) - return ( - state.copy_!.delete(value) || - (state.drafts_.has(value) - ? state.copy_!.delete(state.drafts_.get(value)) - : /* istanbul ignore next */ false) - ) - } - - p.clear = function() { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - if (latest(state).size) { + }) + Object.defineProperty(p, "values", { + configurable: true, + writable: true, + value: function(): IterableIterator { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) prepareSetCopy(state) - markChanged(state) - state.copy_!.clear() + return state.copy_!.values() } - } - - p.values = function(): IterableIterator { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareSetCopy(state) - return state.copy_!.values() - } - - p.entries = function entries(): IterableIterator<[any, any]> { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareSetCopy(state) - return state.copy_!.entries() - } - - p.keys = function(): IterableIterator { - return this.values() - } + }) + Object.defineProperty(p, "entries", { + configurable: true, + writable: true, + value: function entries(): IterableIterator<[any, any]> { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_!.entries() + } + }) + Object.defineProperty(p, "keys", { + configurable: true, + writable: true, + value: function(): IterableIterator { + return this.values() + } + }) - p[iteratorSymbol] = function() { - return this.values() - } + Object.defineProperty(p, iteratorSymbol, { + configurable: true, + writable: true, + value: function() { + return this.values() + } + }) - p.forEach = function forEach(cb: any, thisArg?: any) { - const iterator = this.values() - let result = iterator.next() - while (!result.done) { - cb.call(thisArg, result.value, result.value, this) - result = iterator.next() + Object.defineProperty(p, "forEach", { + configurable: true, + writable: true, + value: function forEach(cb: any, thisArg?: any) { + const iterator = this.values() + let result = iterator.next() + while (!result.done) { + cb.call(thisArg, result.value, result.value, this) + result = iterator.next() + } } - } + }) return DraftSet })(Set) From 4db3210d0ea2a722a01e346570e885f6eea6cec8 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Sun, 6 Mar 2022 11:42:55 +0800 Subject: [PATCH 2/3] fix: resolve review --- src/plugins/mapset.ts | 512 +++++++++++++++++++++--------------------- src/utils/common.ts | 12 +- 2 files changed, 262 insertions(+), 262 deletions(-) diff --git a/src/plugins/mapset.ts b/src/plugins/mapset.ts index 8031f522..40e5dd83 100644 --- a/src/plugins/mapset.ts +++ b/src/plugins/mapset.ts @@ -67,169 +67,160 @@ export function enableMapSet() { } const p = DraftMap.prototype - Object.defineProperty(p, "size", { - get: function() { - return latest(this[DRAFT_STATE]).size + Object.defineProperties(p, { + size: { + get: function() { + return latest(this[DRAFT_STATE]).size + }, + configurable: true }, - // enumerable: false, - configurable: true - }) - - Object.defineProperty(p, "has", { - configurable: true, - writable: true, - value: function(key: any): boolean { - return latest(this[DRAFT_STATE]).has(key) - } - }) - - Object.defineProperty(p, "set", { - configurable: true, - writable: true, - value: function(key: any, value: any) { - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - if (!latest(state).has(key) || latest(state).get(key) !== value) { - prepareMapCopy(state) - markChanged(state) - state.assigned_!.set(key, true) - state.copy_!.set(key, value) - state.assigned_!.set(key, true) + has: { + configurable: true, + writable: true, + value: function(key: any): boolean { + return latest(this[DRAFT_STATE]).has(key) } - return this - } - }) - - Object.defineProperty(p, "delete", { - configurable: true, - writable: true, - value: function(key: any): boolean { - if (!this.has(key)) { - return false - } - - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareMapCopy(state) - markChanged(state) - if (state.base_.has(key)) { - state.assigned_!.set(key, false) - } else { - state.assigned_!.delete(key) + }, + set: { + configurable: true, + writable: true, + value: function(key: any, value: any) { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) + if (!latest(state).has(key) || latest(state).get(key) !== value) { + prepareMapCopy(state) + markChanged(state) + state.assigned_!.set(key, true) + state.copy_!.set(key, value) + state.assigned_!.set(key, true) + } + return this } - state.copy_!.delete(key) - return true - } - }) + }, + delete: { + configurable: true, + writable: true, + value: function(key: any): boolean { + if (!this.has(key)) { + return false + } - Object.defineProperty(p, "clear", { - configurable: true, - writable: true, - value: function() { - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - if (latest(state).size) { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) prepareMapCopy(state) markChanged(state) - state.assigned_ = new Map() - each(state.base_, key => { + if (state.base_.has(key)) { state.assigned_!.set(key, false) + } else { + state.assigned_!.delete(key) + } + state.copy_!.delete(key) + return true + } + }, + clear: { + configurable: true, + writable: true, + value: function() { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareMapCopy(state) + markChanged(state) + state.assigned_ = new Map() + each(state.base_, key => { + state.assigned_!.set(key, false) + }) + state.copy_!.clear() + } + } + }, + forEach: { + configurable: true, + writable: true, + value: function( + cb: (value: any, key: any, self: any) => void, + thisArg?: any + ) { + const state: MapState = this[DRAFT_STATE] + latest(state).forEach((_value: any, key: any, _map: any) => { + cb.call(thisArg, this.get(key), key, this) }) - state.copy_!.clear() } - } - }) - - Object.defineProperty(p, "forEach", { - configurable: true, - writable: true, - value: function( - cb: (value: any, key: any, self: any) => void, - thisArg?: any - ) { - const state: MapState = this[DRAFT_STATE] - latest(state).forEach((_value: any, key: any, _map: any) => { - cb.call(thisArg, this.get(key), key, this) - }) - } - }) - - Object.defineProperty(p, "get", { - configurable: true, - writable: true, - value: function(key: any): any { - const state: MapState = this[DRAFT_STATE] - assertUnrevoked(state) - const value = latest(state).get(key) - if (state.finalized_ || !isDraftable(value)) { - return value + }, + get: { + configurable: true, + writable: true, + value: function(key: any): any { + const state: MapState = this[DRAFT_STATE] + assertUnrevoked(state) + const value = latest(state).get(key) + if (state.finalized_ || !isDraftable(value)) { + return value + } + if (value !== state.base_.get(key)) { + return value // either already drafted or reassigned + } + // despite what it looks, this creates a draft only once, see above condition + const draft = createProxy(state.scope_.immer_, value, state) + prepareMapCopy(state) + state.copy_!.set(key, draft) + return draft } - if (value !== state.base_.get(key)) { - return value // either already drafted or reassigned + }, + keys: { + configurable: true, + writable: true, + value: function(): IterableIterator { + return latest(this[DRAFT_STATE]).keys() } - // despite what it looks, this creates a draft only once, see above condition - const draft = createProxy(state.scope_.immer_, value, state) - prepareMapCopy(state) - state.copy_!.set(key, draft) - return draft - } - }) - - Object.defineProperty(p, "keys", { - configurable: true, - writable: true, - value: function(): IterableIterator { - return latest(this[DRAFT_STATE]).keys() - } - }) - - Object.defineProperty(p, "values", { - configurable: true, - writable: true, - value: function(): IterableIterator { - const iterator = this.keys() - return { - [iteratorSymbol]: () => this.values(), - next: () => { - const r = iterator.next() - /* istanbul ignore next */ - if (r.done) return r - const value = this.get(r.value) - return { - done: false, - value + }, + values: { + configurable: true, + writable: true, + value: function(): IterableIterator { + const iterator = this.keys() + return { + [iteratorSymbol]: () => this.values(), + next: () => { + const r = iterator.next() + /* istanbul ignore next */ + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value + } } - } - } as any - } - }) - - Object.defineProperty(p, "entries", { - configurable: true, - writable: true, - value: function(): IterableIterator<[any, any]> { - const iterator = this.keys() - return { - [iteratorSymbol]: () => this.entries(), - next: () => { - const r = iterator.next() - /* istanbul ignore next */ - if (r.done) return r - const value = this.get(r.value) - return { - done: false, - value: [r.value, value] + } as any + } + }, + entries: { + configurable: true, + writable: true, + value: function(): IterableIterator<[any, any]> { + const iterator = this.keys() + return { + [iteratorSymbol]: () => this.entries(), + next: () => { + const r = iterator.next() + /* istanbul ignore next */ + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value: [r.value, value] + } } - } - } as any - } - }) - - Object.defineProperty(p, iteratorSymbol, { - configurable: true, - writable: true, - value: function() { - return this.entries() + } as any + } + }, + [iteratorSymbol]: { + configurable: true, + writable: true, + value: function() { + return this.entries() + } } }) @@ -269,124 +260,123 @@ export function enableMapSet() { } const p = DraftSet.prototype - Object.defineProperty(p, "size", { - get: function() { - return latest(this[DRAFT_STATE]).size - } - // enumerable: true, - }) - - Object.defineProperty(p, "has", { - configurable: true, - writable: true, - value: function(value: any): boolean { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - // bit of trickery here, to be able to recognize both the value, and the draft of its value - if (!state.copy_) { - return state.base_.has(value) + Object.defineProperties(p, { + size: { + get: function() { + return latest(this[DRAFT_STATE]).size + }, + configurable: true + }, + has: { + configurable: true, + writable: true, + value: function(value: any): boolean { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + // bit of trickery here, to be able to recognize both the value, and the draft of its value + if (!state.copy_) { + return state.base_.has(value) + } + if (state.copy_.has(value)) return true + if ( + state.drafts_.has(value) && + state.copy_.has(state.drafts_.get(value)) + ) + return true + return false } - if (state.copy_.has(value)) return true - if ( - state.drafts_.has(value) && - state.copy_.has(state.drafts_.get(value)) - ) - return true - return false - } - }) - Object.defineProperty(p, "add", { - configurable: true, - writable: true, - value: function(value: any): any { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - if (!this.has(value)) { + }, + add: { + configurable: true, + writable: true, + value: function(value: any): any { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + if (!this.has(value)) { + prepareSetCopy(state) + markChanged(state) + state.copy_!.add(value) + } + return this + } + }, + delete: { + configurable: true, + writable: true, + value: function(value: any): any { + if (!this.has(value)) { + return false + } + + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) prepareSetCopy(state) markChanged(state) - state.copy_!.add(value) + return ( + state.copy_!.delete(value) || + (state.drafts_.has(value) + ? state.copy_!.delete(state.drafts_.get(value)) + : /* istanbul ignore next */ false) + ) } - return this - } - }) - Object.defineProperty(p, "delete", { - configurable: true, - writable: true, - value: function(value: any): any { - if (!this.has(value)) { - return false + }, + clear: { + configurable: true, + writable: true, + value: function() { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareSetCopy(state) + markChanged(state) + state.copy_!.clear() + } } - - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareSetCopy(state) - markChanged(state) - return ( - state.copy_!.delete(value) || - (state.drafts_.has(value) - ? state.copy_!.delete(state.drafts_.get(value)) - : /* istanbul ignore next */ false) - ) - } - }) - Object.defineProperty(p, "clear", { - configurable: true, - writable: true, - value: function() { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - if (latest(state).size) { + }, + values: { + configurable: true, + writable: true, + value: function(): IterableIterator { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) prepareSetCopy(state) - markChanged(state) - state.copy_!.clear() + return state.copy_!.values() } - } - }) - Object.defineProperty(p, "values", { - configurable: true, - writable: true, - value: function(): IterableIterator { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareSetCopy(state) - return state.copy_!.values() - } - }) - Object.defineProperty(p, "entries", { - configurable: true, - writable: true, - value: function entries(): IterableIterator<[any, any]> { - const state: SetState = this[DRAFT_STATE] - assertUnrevoked(state) - prepareSetCopy(state) - return state.copy_!.entries() - } - }) - Object.defineProperty(p, "keys", { - configurable: true, - writable: true, - value: function(): IterableIterator { - return this.values() - } - }) - - Object.defineProperty(p, iteratorSymbol, { - configurable: true, - writable: true, - value: function() { - return this.values() - } - }) - - Object.defineProperty(p, "forEach", { - configurable: true, - writable: true, - value: function forEach(cb: any, thisArg?: any) { - const iterator = this.values() - let result = iterator.next() - while (!result.done) { - cb.call(thisArg, result.value, result.value, this) - result = iterator.next() + }, + entries: { + configurable: true, + writable: true, + value: function entries(): IterableIterator<[any, any]> { + const state: SetState = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_!.entries() + } + }, + keys: { + configurable: true, + writable: true, + value: function(): IterableIterator { + return this.values() + } + }, + [iteratorSymbol]: { + configurable: true, + writable: true, + value: function() { + return this.values() + } + }, + forEach: { + configurable: true, + writable: true, + value: function forEach(cb: any, thisArg?: any) { + const iterator = this.values() + let result = iterator.next() + while (!result.done) { + cb.call(thisArg, result.value, result.value, this) + result = iterator.next() + } } } }) diff --git a/src/utils/common.ts b/src/utils/common.ts index dae5064e..d13153c9 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -199,7 +199,17 @@ export function freeze(obj: T, deep?: boolean): T export function freeze(obj: any, deep: boolean = false): T { if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj if (getArchtype(obj) > 1 /* Map or Set */) { - obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any + const desc: PropertyDescriptor = { + configurable: true, + writable: true, + value: dontMutateFrozenCollections, + } + Object.defineProperties(obj, { + set: desc, + add: desc, + clear: desc, + delete: desc, + }); } Object.freeze(obj) if (deep) each(obj, (key, value) => freeze(value, true), true) From f4a396432546d54e0fc9568f3041b9c07aceb0fa Mon Sep 17 00:00:00 2001 From: Jack Works Date: Sun, 6 Mar 2022 12:00:33 +0800 Subject: [PATCH 3/3] fix: resolve review --- src/utils/common.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/common.ts b/src/utils/common.ts index d13153c9..9586de0b 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -202,14 +202,14 @@ export function freeze(obj: any, deep: boolean = false): T { const desc: PropertyDescriptor = { configurable: true, writable: true, - value: dontMutateFrozenCollections, + value: dontMutateFrozenCollections } Object.defineProperties(obj, { set: desc, add: desc, clear: desc, - delete: desc, - }); + delete: desc + }) } Object.freeze(obj) if (deep) each(obj, (key, value) => freeze(value, true), true)