Mangle properties, -114 bytes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parent 472ab66 · Browse files · 16 files·+439 added−356 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
16 files+439 added−356 removed
- tests:+8 added−6 removed
- other:+431 added−350 removed
Provenance
- Commit
bfa7ddd- Tree
ff83918- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
472ab66
16 files changed+439 added−356 removed
modified:__tests__/base.js+2 added-2 removed
462 unmodified lines463 it("can assign by key", () => {464 const nextState = produce(baseState, s => {465 // Map.prototype.set should return the Map itself466 const res = s.aMap.set("force", true)467- if (!global.USES_BUILD) expect(res).toBe(s.aMap[DRAFT_STATE].draft)467+ if (!global.USES_BUILD) expect(res).toBe(s.aMap[DRAFT_STATE].draft_)468 })469 expect(nextState).not.toBe(baseState)470 expect(nextState.aMap).not.toBe(baseState.aMap)471 expect(nextState.aMap.get("force")).toEqual(true)316 unmodified lines788 it("can add new items", () => {789 const nextState = produce(baseState, s => {790 // Set.prototype.set should return the Set itself791 const res = s.aSet.add("force")792- if (!global.USES_BUILD) expect(res).toBe(s.aSet[DRAFT_STATE].draft)792+ if (!global.USES_BUILD) expect(res).toBe(s.aSet[DRAFT_STATE].draft_)793 })794 expect(nextState).not.toBe(baseState)795 expect(nextState.aSet).not.toBe(baseState.aSet)796 expect(baseState.aSet.has("force")).toBe(false)1303 unmodified linesmodified:__tests__/empty.ts+1 added-1 removed
85 unmodified lines8687888990909192939457 unmodified lines85 unmodified lines // Map.prototype.set should return the Map itself const res = s.aMap.set("force", true) // @ts-ignore if (!global.USES_BUILD) expect(res).toBe((s.aMap as any)[DRAFT_STATE].draft) expect(res).toBe((s.aMap as any)[DRAFT_STATE].draft_) }) expect(nextState).not.toBe(baseState) expect(nextState.aMap).not.toBe(baseState.aMap) expect(nextState.aMap.get("force")).toEqual(true)57 unmodified linesmodified:__tests__/hooks.js+5 added-3 removed
305 unmodified lines306 })307 })308 309 describe("onCopy()", () => {310+ if (global.USES_BUILD) return311+312 let calls313 beforeEach(() => {314 calls = []315 onCopy.mockImplementation(s => {314- calls.push(s.base)316+ calls.push(s.base_)317 })318 })319 320 useSharedTests(() => onCopy)27 unmodified lines348 it("is called before the parent is frozen", () => {349 const hook = getHook()350 hook.mockImplementation(s => {351 // Parent object must not be frozen.350- expect(Object.isFrozen(s.base)).toBeFalsy()352+ if (!global.USES_BUILD) expect(Object.isFrozen(s.base_)).toBeFalsy()353 })354 produce({a: {b: {c: 0}}}, s => {355 if (hook == onDelete) delete s.a.b.c356 else s.a.b.c = 114 unmodified lines371 372 // For defusing draft proxies.373 function defuseProxies(fn) {374 return Object.assign((...args) => {373- expect(args[0].finalized).toBeTruthy()375+ if (!global.USES_BUILD) expect(args[0].finalized_).toBeTruthy()376 args[0].draft = args[0].drafts = null377 fn(...args)378 }, fn)379 }12 unmodified linesmodified:src/plugins/es5.ts+81 added-71 removed
27 unmodified lines28 scope: ImmerScope,29 result: any,30 isReplaced: boolean31 ) {32- scope.drafts!.forEach((draft: any) => {33- draft[DRAFT_STATE].finalizing = true32+ scope.drafts_!.forEach((draft: any) => {33+ ;(draft[DRAFT_STATE] as ES5State).finalizing_ = true34 })35 if (!isReplaced) {36- if (scope.patches) {37- markChangesRecursively(scope.drafts![0])36+ if (scope.patches_) {37+ markChangesRecursively(scope.drafts_![0])38 }39 // This is faster when we don't care about which attributes changed.40- markChangesSweep(scope.drafts)40+ markChangesSweep(scope.drafts_)41 }42 // When a child draft is returned, look for changes.43- else if (isDraft(result) && result[DRAFT_STATE].scope === scope) {44- markChangesSweep(scope.drafts)43+ else if (44+ isDraft(result) &&45+ (result[DRAFT_STATE] as ES5State).scope_ === scope46+ ) {47+ markChangesSweep(scope.drafts_)48 }49 }50 51 function createES5Proxy<T>(52 base: T,53 parent?: ImmerState54 ): Drafted<T, ES5ObjectState | ES5ArrayState> {55 const isArray = Array.isArray(base)53- const draft = clonePotentialDraft(base)56+ const draft: any = clonePotentialDraft(base)57 58 each(draft, prop => {59 proxyProperty(draft, prop, isArray || isEnumerable(base, prop))60 })61 62 const state: ES5ObjectState | ES5ArrayState = {60- type: isArray ? ProxyType.ES5Array : (ProxyType.ES5Object as any),61- scope: parent ? parent.scope : ImmerScope.current!,62- modified: false,63- finalizing: false,64- finalized: false,65- assigned: {},66- parent,67- base,68- draft,69- copy: null,70- revoked: false,71- isManual: false63+ type_: isArray ? ProxyType.ES5Array : (ProxyType.ES5Object as any),64+ scope_: parent ? parent.scope_ : ImmerScope.current_!,65+ modified_: false,66+ finalizing_: false,67+ finalized_: false,68+ assigned_: {},69+ parent_: parent,70+ base_: base,71+ draft_: draft,72+ copy_: null,73+ revoked_: false,74+ isManual_: false75 }76 77 createHiddenProperty(draft, DRAFT_STATE, state)78 return draft79 }80 81 // Access a property without creating an Immer draft.82 function peek(draft: Drafted, prop: PropertyKey) {80- const state = draft[DRAFT_STATE]81- if (state && !state.finalizing) {82- state.finalizing = true83+ const state: ES5State = draft[DRAFT_STATE]84+ if (state && !state.finalizing_) {85+ state.finalizing_ = true86 const value = draft[prop]84- state.finalizing = false87+ state.finalizing_ = false88 return value89 }90 return draft[prop]91 }92 93 function get(state: ES5State, prop: string | number) {94 assertUnrevoked(state)95 const value = peek(latest(state), prop)93- if (state.finalizing) return value96+ if (state.finalizing_) return value97 // Create a draft if the value is unmodified.95- if (value === peek(state.base, prop) && isDraftable(value)) {98+ if (value === peek(state.base_, prop) && isDraftable(value)) {99 prepareCopy(state)100 // @ts-ignore98- return (state.copy![prop] = createProxy(state.scope.immer, value, state))101+ return (state.copy_![prop] = createProxy(102+ state.scope_.immer_,103+ value,104+ state105+ ))106 }107 return value108 }109 110 function set(state: ES5State, prop: string | number, value: any) {111 assertUnrevoked(state)105- state.assigned[prop] = true106- if (!state.modified) {112+ state.assigned_[prop] = true113+ if (!state.modified_) {114 if (is(value, peek(latest(state), prop))) return115 markChangedES5(state)116 prepareCopy(state)117 }118 // @ts-ignore112- state.copy![prop] = value119+ state.copy_![prop] = value120 }121 122 function markChangedES5(state: ImmerState) {116- if (!state.modified) {117- state.modified = true118- if (state.parent) markChangedES5(state.parent)123+ if (!state.modified_) {124+ state.modified_ = true125+ if (state.parent_) markChangedES5(state.parent_)126 }127 }128 129 function prepareCopy(state: ES5State) {123- if (!state.copy) state.copy = clonePotentialDraft(state.base)130+ if (!state.copy_) state.copy_ = clonePotentialDraft(state.base_)131 }132 133 function clonePotentialDraft(base: Objectish) {127- const state = base && (base as any)[DRAFT_STATE]134+ const state: ES5State | undefined = base && (base as any)[DRAFT_STATE]135 if (state) {129- state.finalizing = true130- const draft = shallowCopy(state.draft, true)131- state.finalizing = false136+ state.finalizing_ = true137+ const draft = shallowCopy(state.draft_, true)138+ state.finalizing_ = false139 return draft140 }141 return shallowCopy(base)142 }31 unmodified lines174 // were accessed. By processing drafts in reverse natural order, we have a175 // better chance of processing leaf nodes first. When a leaf node is known to176 // have changed, we can avoid any traversal of its ancestor nodes.177 for (let i = drafts.length - 1; i >= 0; i--) {171- const state = drafts[i][DRAFT_STATE]172- if (!state.modified) {173- switch (state.type) {178+ const state: ES5State = drafts[i][DRAFT_STATE]179+ if (!state.modified_) {180+ switch (state.type_) {181 case ProxyType.ES5Array:182 if (hasArrayChanges(state)) markChangedES5(state)183 break184 case ProxyType.ES5Object:5 unmodified lines190 }191 192 function markChangesRecursively(object: any) {193 if (!object || typeof object !== "object") return187- const state = object[DRAFT_STATE]194+ const state: ES5State | undefined = object[DRAFT_STATE]195 if (!state) return189- const {base, draft, assigned, type} = state190- if (type === ProxyType.ES5Object) {196+ const {base_, draft_, assigned_, type_} = state197+ if (type_ === ProxyType.ES5Object) {198 // Look for added keys.199 // TODO: looks quite duplicate to hasObjectChanges,200 // probably there is a faster way to detect changes, as sweep + recurse seems to do some201 // unnecessary work.202 // also: probably we can store the information we detect here, to speed up tree finalization!196- each(draft, key => {203+ each(draft_, key => {204 if ((key as any) === DRAFT_STATE) return205 // The `undefined` check is a fast path for pre-existing keys.199- if (base[key] === undefined && !has(base, key)) {200- assigned[key] = true206+ if ((base_ as any)[key] === undefined && !has(base_, key)) {207+ assigned_[key] = true208 markChangedES5(state)202- } else if (!assigned[key]) {209+ } else if (!assigned_[key]) {210 // Only untouched properties trigger recursion.204- markChangesRecursively(draft[key])211+ markChangesRecursively(draft_[key])212 }213 })214 // Look for removed keys.208- each(base, key => {215+ each(base_, key => {216 // The `undefined` check is a fast path for pre-existing keys.210- if (draft[key] === undefined && !has(draft, key)) {211- assigned[key] = false217+ if (draft_[key] === undefined && !has(draft_, key)) {218+ assigned_[key] = false219 markChangedES5(state)220 }221 })215- } else if (type === ProxyType.ES5Array) {216- if (hasArrayChanges(state)) {222+ } else if (type_ === ProxyType.ES5Array) {223+ if (hasArrayChanges(state as ES5ArrayState)) {224 markChangedES5(state)218- assigned.length = true225+ assigned_.length = true226 }227 221- if (draft.length < base.length) {222- for (let i = draft.length; i < base.length; i++) assigned[i] = false228+ if (draft_.length < base_.length) {229+ for (let i = draft_.length; i < base_.length; i++) assigned_[i] = false230 } else {224- for (let i = base.length; i < draft.length; i++) assigned[i] = true231+ for (let i = base_.length; i < draft_.length; i++) assigned_[i] = true232 }233 234 // Minimum count is enough, the other parts has been processed.228- const min = Math.min(draft.length, base.length)235+ const min = Math.min(draft_.length, base_.length)236 237 for (let i = 0; i < min; i++) {238 // Only untouched indices trigger recursion.232- if (assigned[i] === undefined) markChangesRecursively(draft[i])239+ if (assigned_[i] === undefined) markChangesRecursively(draft_[i])240 }241 }242 }243 244 function hasObjectChanges(state: ES5ObjectState) {238- const {base, draft} = state245+ const {base_, draft_} = state246 247 // Search for added keys and changed keys. Start at the back, because248 // non-numeric keys are ordered by time of definition on the object.242- const keys = Object.keys(draft)249+ const keys = Object.keys(draft_)250 for (let i = keys.length - 1; i >= 0; i--) {251 const key = keys[i]245- const baseValue = base[key]252+ const baseValue = base_[key]253 // The `undefined` check is a fast path for pre-existing keys.247- if (baseValue === undefined && !has(base, key)) {254+ if (baseValue === undefined && !has(base_, key)) {255 return true256 }257 // Once a base key is deleted, future changes go undetected, because its258 // descriptor is erased. This branch detects any missed changes.259 else {253- const value = draft[key]254- const state = value && value[DRAFT_STATE]255- if (state ? state.base !== baseValue : !is(value, baseValue)) {260+ const value = draft_[key]261+ const state: ImmerState = value && value[DRAFT_STATE]262+ if (state ? state.base_ !== baseValue : !is(value, baseValue)) {263 return true264 }265 }266 }267 268 // At this point, no keys were added or changed.269 // Compare key count to determine if keys were deleted.263- return keys.length !== Object.keys(base).length270+ return keys.length !== Object.keys(base_).length271 }272 273 function hasArrayChanges(state: ES5ArrayState) {267- const {draft} = state268- if (draft.length !== state.base.length) return true274+ const {draft_} = state275+ if (draft_.length !== state.base_.length) return true276 // See #116277 // If we first shorten the length, our array interceptors will be removed.278 // If after that new items are added, result in the same original length,279 // those last items will have no intercepting property.280 // So if there is no own descriptor on the last position, we know that items were removed and added281 // N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check282 // the last one276- const descriptor = Object.getOwnPropertyDescriptor(draft, draft.length - 1)283+ const descriptor = Object.getOwnPropertyDescriptor(284+ draft_,285+ draft_.length - 1286+ )287 // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)288 if (descriptor && !descriptor.get) return true289 // For all other cases, we don't have to compare, as they would have been picked up by the index setters290 return false8 unmodified linesmodified:src/plugins/mapset.ts+76 added-76 removed
48 unmodified lines49 __extends(DraftMap, _super)50 // Create class manually, cause #50251 function DraftMap(this: any, target: AnyMap, parent?: ImmerState): any {52 this[DRAFT_STATE] = {53- type: ProxyType.Map,54- parent,55- scope: parent ? parent.scope : ImmerScope.current!,56- modified: false,57- finalized: false,58- copy: undefined,59- assigned: undefined,60- base: target,61- draft: this as any,62- isManual: false,63- revoked: false64- }53+ type_: ProxyType.Map,54+ parent_: parent,55+ scope_: parent ? parent.scope_ : ImmerScope.current_!,56+ modified_: false,57+ finalized_: false,58+ copy_: undefined,59+ assigned_: undefined,60+ base_: target,61+ draft_: this as any,62+ isManual_: false,63+ revoked_: false64+ } as MapState65 return this66 }67 const p = DraftMap.prototype68 10 unmodified lines79 return latest(this[DRAFT_STATE]).has(key)80 }81 82 p.set = function(key: any, value: any) {83- const state = this[DRAFT_STATE]83+ const state: MapState = this[DRAFT_STATE]84 assertUnrevoked(state)85 if (latest(state).get(key) !== value) {86 prepareMapCopy(state)87- markChanged(state.scope.immer, state)88- state.assigned!.set(key, true)89- state.copy!.set(key, value)90- state.assigned!.set(key, true)87+ markChanged(state.scope_.immer_, state)88+ state.assigned_!.set(key, true)89+ state.copy_!.set(key, value)90+ state.assigned_!.set(key, true)91 }92 return this93 }94 1 unmodified line96 if (!this.has(key)) {97 return false98 }99 100- const state = this[DRAFT_STATE]100+ const state: MapState = this[DRAFT_STATE]101 assertUnrevoked(state)102 prepareMapCopy(state)103- markChanged(state.scope.immer, state)104- state.assigned!.set(key, false)105- state.copy!.delete(key)103+ markChanged(state.scope_.immer_, state)104+ state.assigned_!.set(key, false)105+ state.copy_!.delete(key)106 return true107 }108 109 p.clear = function() {110- const state = this[DRAFT_STATE]110+ const state: MapState = this[DRAFT_STATE]111 assertUnrevoked(state)112 prepareMapCopy(state)113- markChanged(state.scope.immer, state)114- state.assigned = new Map()115- return state.copy!.clear()113+ markChanged(state.scope_.immer_, state)114+ state.assigned_ = new Map()115+ return state.copy_!.clear()116 }117 118 p.forEach = function(119 cb: (value: any, key: any, self: any) => void,120 thisArg?: any121 ) {122- const state = this[DRAFT_STATE]122+ const state: MapState = this[DRAFT_STATE]123 latest(state).forEach((_value: any, key: any, _map: any) => {124 cb.call(thisArg, this.get(key), key, this)125 })126 }127 128 p.get = function(key: any): any {129- const state = this[DRAFT_STATE]129+ const state: MapState = this[DRAFT_STATE]130 assertUnrevoked(state)131 const value = latest(state).get(key)132- if (state.finalized || !isDraftable(value)) {132+ if (state.finalized_ || !isDraftable(value)) {133 return value134 }135- if (value !== state.base.get(key)) {135+ if (value !== state.base_.get(key)) {136 return value // either already drafted or reassigned137 }138 // despite what it looks, this creates a draft only once, see above condition139- const draft = createProxy(state.scope.immer, value, state)139+ const draft = createProxy(state.scope_.immer_, value, state)140 prepareMapCopy(state)141- state.copy!.set(key, draft)141+ state.copy_!.set(key, draft)142 return draft143 }144 145 p.keys = function(): IterableIterator<any> {46 unmodified lines192 return new DraftMap(target, parent)193 }194 195 function prepareMapCopy(state: MapState) {196- if (!state.copy) {197- state.assigned = new Map()198- state.copy = new Map(state.base)196+ if (!state.copy_) {197+ state.assigned_ = new Map()198+ state.copy_ = new Map(state.base_)199 }200 }201 202 const DraftSet = (function(_super) {2 unmodified lines205 __extends(DraftSet, _super)206 // Create class manually, cause #502207 function DraftSet(this: any, target: AnySet, parent?: ImmerState) {208 this[DRAFT_STATE] = {209- type: ProxyType.Set,210- parent,211- scope: parent ? parent.scope : ImmerScope.current!,212- modified: false,213- finalized: false,214- copy: undefined,215- base: target,216- draft: this,217- drafts: new Map(),218- revoked: false,219- isManual: false220- }209+ type_: ProxyType.Set,210+ parent_: parent,211+ scope_: parent ? parent.scope_ : ImmerScope.current_!,212+ modified_: false,213+ finalized_: false,214+ copy_: undefined,215+ base_: target,216+ draft_: this,217+ drafts_: new Map(),218+ revoked_: false,219+ isManual_: false220+ } as SetState221 return this222 }223 const p = DraftSet.prototype224 5 unmodified lines230 configurable: true231 })232 233 p.has = function(value: any): boolean {234- const state = this[DRAFT_STATE]234+ const state: SetState = this[DRAFT_STATE]235 assertUnrevoked(state)236 // bit of trickery here, to be able to recognize both the value, and the draft of its value237- if (!state.copy) {238- return state.base.has(value)237+ if (!state.copy_) {238+ return state.base_.has(value)239 }240- if (state.copy.has(value)) return true241- if (state.drafts.has(value) && state.copy.has(state.drafts.get(value)))240+ if (state.copy_.has(value)) return true241+ if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))242 return true243 return false244 }245 246 p.add = function(value: any): any {247- const state = this[DRAFT_STATE]247+ const state: SetState = this[DRAFT_STATE]248 assertUnrevoked(state)249- if (state.copy) {250- state.copy.add(value)251- } else if (!state.base.has(value)) {249+ if (state.copy_) {250+ state.copy_.add(value)251+ } else if (!state.base_.has(value)) {252 prepareSetCopy(state)253- markChanged(state.scope.immer, state)254- state.copy!.add(value)253+ markChanged(state.scope_.immer_, state)254+ state.copy_!.add(value)255 }256 return this257 }258 1 unmodified line260 if (!this.has(value)) {261 return false262 }263 264- const state = this[DRAFT_STATE]264+ const state: SetState = this[DRAFT_STATE]265 assertUnrevoked(state)266 prepareSetCopy(state)267- markChanged(state.scope.immer, state)267+ markChanged(state.scope_.immer_, state)268 return (269- state.copy!.delete(value) ||270- (state.drafts.has(value)271- ? state.copy!.delete(state.drafts.get(value))269+ state.copy_!.delete(value) ||270+ (state.drafts_.has(value)271+ ? state.copy_!.delete(state.drafts_.get(value))272 : /* istanbul ignore next */ false)273 )274 }275 276 p.clear = function() {277- const state = this[DRAFT_STATE]277+ const state: SetState = this[DRAFT_STATE]278 assertUnrevoked(state)279 prepareSetCopy(state)280- markChanged(state.scope.immer, state)281- return state.copy!.clear()280+ markChanged(state.scope_.immer_, state)281+ return state.copy_!.clear()282 }283 284 p.values = function(): IterableIterator<any> {285- const state = this[DRAFT_STATE]285+ const state: SetState = this[DRAFT_STATE]286 assertUnrevoked(state)287 prepareSetCopy(state)288- return state.copy!.values()288+ return state.copy_!.values()289 }290 291 p.entries = function entries(): IterableIterator<[any, any]> {292- const state = this[DRAFT_STATE]292+ const state: SetState = this[DRAFT_STATE]293 assertUnrevoked(state)294 prepareSetCopy(state)295- return state.copy!.entries()295+ return state.copy_!.entries()296 }297 298 p.keys = function(): IterableIterator<any> {299 return this.values()20 unmodified lines320 return new DraftSet(target, parent)321 }322 323 function prepareSetCopy(state: SetState) {324- if (!state.copy) {324+ if (!state.copy_) {325 // create drafts for all entries to preserve insertion order326- state.copy = new Set()327- state.base.forEach(value => {326+ state.copy_ = new Set()327+ state.base_.forEach(value => {328 if (isDraftable(value)) {329- const draft = createProxy(state.scope.immer, value, state)330- state.drafts.set(value, draft)331- state.copy!.add(draft)329+ const draft = createProxy(state.scope_.immer_, value, state)330+ state.drafts_.set(value, draft)331+ state.copy_!.add(draft)332 } else {333- state.copy!.add(value)333+ state.copy_!.add(value)334 }335 })336 }337 }3 unmodified linesmodified:src/plugins/patches.ts+23 added-23 removed
27 unmodified lines28 basePath: PatchPath,29 patches: Patch[],30 inversePatches: Patch[]31 ): void {32- switch (state.type) {32+ switch (state.type_) {33 case ProxyType.ProxyObject:34 case ProxyType.ES5Object:35 case ProxyType.Map:36 return generatePatchesFromAssigned(20 unmodified lines57 basePath: PatchPath,58 patches: Patch[],59 inversePatches: Patch[]60 ) {61- let {base, assigned, copy} = state61+ let {base_, assigned_, copy_} = state62 /* istanbul ignore next */63- if (!copy) die()63+ if (!copy_) die()64 65 // Reduce complexity by ensuring `base` is never longer.66- if (copy.length < base.length) {66+ if (copy_.length < base_.length) {67 // @ts-ignore68- ;[base, copy] = [copy, base]68+ ;[base_, copy_] = [copy_, base_]69 ;[patches, inversePatches] = [inversePatches, patches]70 }71 72- const delta = copy.length - base.length72+ const delta = copy_.length - base_.length73 74 // Find the first replaced index.75 let start = 076- while (base[start] === copy[start] && start < base.length) {76+ while (base_[start] === copy_[start] && start < base_.length) {77 ++start78 }79 80 // Find the last replaced index. Search from the end to optimize splice patches.81- let end = base.length82- while (end > start && base[end - 1] === copy[end + delta - 1]) {81+ let end = base_.length82+ while (end > start && base_[end - 1] === copy_[end + delta - 1]) {83 --end84 }85 86 // Process replaced indices.87 for (let i = start; i < end; ++i) {88- if (assigned[i] && copy[i] !== base[i]) {88+ if (assigned_[i] && copy_[i] !== base_[i]) {89 const path = basePath.concat([i])90 patches.push({91 op: "replace",92 path,93- value: copy[i]93+ value: copy_[i]94 })95 inversePatches.push({96 op: "replace",97 path,98- value: base[i]98+ value: base_[i]99 })100 }101 }102 4 unmodified lines107 const path = basePath.concat([i])108 patches[replaceCount + i - end] = {109 op: "add",110 path,111- value: copy[i]111+ value: copy_[i]112 }113 inversePatches.push({114 op: "remove",115 path7 unmodified lines123 basePath: PatchPath,124 patches: Patch[],125 inversePatches: Patch[]126 ) {127- const {base, copy} = state128- each(state.assigned!, (key, assignedValue) => {129- const origValue = get(base, key)130- const value = get(copy!, key)131- const op = !assignedValue ? "remove" : has(base, key) ? "replace" : "add"127+ const {base_, copy_} = state128+ each(state.assigned_!, (key, assignedValue) => {129+ const origValue = get(base_, key)130+ const value = get(copy_!, key)131+ const op = !assignedValue ? "remove" : has(base_, key) ? "replace" : "add"132 if (origValue === value && op === "replace") return133 const path = basePath.concat(key as any)134 patches.push(op === "remove" ? {op, path} : {op, path, value})135 inversePatches.push(11 unmodified lines147 basePath: PatchPath,148 patches: Patch[],149 inversePatches: Patch[]150 ) {151- let {base, copy} = state151+ let {base_, copy_} = state152 153 let i = 0154- base.forEach(value => {155- if (!copy!.has(value)) {154+ base_.forEach(value => {155+ if (!copy_!.has(value)) {156 const path = basePath.concat([i])157 patches.push({158 op: "remove",159 path,7 unmodified lines167 }168 i++169 })170 i = 0171- copy!.forEach(value => {172- if (!base.has(value)) {171+ copy_!.forEach(value => {172+ if (!base_.has(value)) {173 const path = basePath.concat([i])174 patches.push({175 op: "add",176 path,92 unmodified linesmodified:src/common.ts+3 added-3 removed
45 unmodified lines46 /*#__PURE__*/47 export function original<T>(value: T): T | undefined48 export function original(value: Drafted<any>): any {49 if (value && value[DRAFT_STATE]) {50- return value[DRAFT_STATE].base as any50+ return value[DRAFT_STATE].base_ as any51 }52 // otherwise return undefined53 }54 101 unmodified lines156 return hasSet && target instanceof Set157 }158 /*#__PURE__*/159 export function latest(state: ImmerState): any {160- return state.copy || state.base160+ return state.copy_ || state.base_161 }162 163 /*#__PURE__*/164 export function shallowCopy<T extends AnyObject | AnyArray>(60 unmodified lines225 }226 227 export function assertUnrevoked(state: any /*ES5State | MapState | SetState*/) {228 invariant(229- !state.revoked,229+ !state.revoked_,230 "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " +231 JSON.stringify(latest(state))232 )233 }modified:src/finalize.ts+39 added-39 removed
22 unmodified lines23 } from "./internal"24 import invariant from "tiny-invariant"25 26 export function processResult(immer: Immer, result: any, scope: ImmerScope) {27- const baseDraft = scope.drafts![0]27+ const baseDraft = scope.drafts_![0]28 const isReplaced = result !== undefined && result !== baseDraft29 willFinalize(immer, scope, result, isReplaced)30 if (isReplaced) {31- if (baseDraft[DRAFT_STATE].modified) {32- scope.revoke()31+ if (baseDraft[DRAFT_STATE].modified_) {32+ scope.revoke_()33 invariant(false, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.") // prettier-ignore34 }35 if (isDraftable(result)) {36 // Finalize the result in case it contains (or is) a subset of the draft.37 result = finalize(immer, result, scope)38- if (!scope.parent) maybeFreeze(immer, result)38+ if (!scope.parent_) maybeFreeze(immer, result)39 }40- if (scope.patches) {41- scope.patches.push({40+ if (scope.patches_) {41+ scope.patches_.push({42 op: "replace",43 path: [],44 value: result45 })46- scope.inversePatches!.push({46+ scope.inversePatches_!.push({47 op: "replace",48 path: [],49- value: baseDraft[DRAFT_STATE].base49+ value: (baseDraft[DRAFT_STATE] as ImmerState).base_50 })51 }52 } else {53 // Finalize the base draft.54 result = finalize(immer, baseDraft, scope, [])55 }56- scope.revoke()57- if (scope.patches) {58- scope.patchListener!(scope.patches, scope.inversePatches!)56+ scope.revoke_()57+ if (scope.patches_) {58+ scope.patchListener_!(scope.patches_, scope.inversePatches_!)59 }60 return result !== NOTHING ? result : undefined61 }62 2 unmodified lines65 draft: Drafted,66 scope: ImmerScope,67 path?: PatchPath68 ) {69- const state = draft[DRAFT_STATE]69+ const state: ImmerState = draft[DRAFT_STATE]70 if (!state) {71 if (Object.isFrozen(draft)) return draft72 return finalizeTree(immer, draft, scope)73 }74 // Never finalize drafts owned by another scope.75- if (state.scope !== scope) {75+ if (state.scope_ !== scope) {76 return draft77 }78- if (!state.modified) {79- maybeFreeze(immer, state.base, true)80- return state.base78+ if (!state.modified_) {79+ maybeFreeze(immer, state.base_, true)80+ return state.base_81 }82- if (!state.finalized) {83- state.finalized = true84- finalizeTree(immer, state.draft, scope, path)82+ if (!state.finalized_) {83+ state.finalized_ = true84+ finalizeTree(immer, state.draft_, scope, path)85 86 // We cannot really delete anything inside of a Set. We can only replace the whole Set.87- if (immer.onDelete && state.type !== ProxyType.Set) {87+ if (immer.onDelete && state.type_ !== ProxyType.Set) {88 // The `assigned` object is unreliable with ES5 drafts.89 if (immer.useProxies) {90- const {assigned} = state91- each(assigned, (prop, exists) => {90+ const {assigned_} = state91+ each(assigned_ as any, (prop, exists) => {92 if (!exists) immer.onDelete!(state, prop as any)93 })94 } else {95- const {base, copy} = state96- each(base, prop => {97- if (!has(copy, prop)) immer.onDelete!(state, prop as any)95+ const {base_, copy_} = state96+ each(base_, prop => {97+ if (!has(copy_, prop)) immer.onDelete!(state, prop as any)98 })99 }100 }101 if (immer.onCopy) {1 unmodified line103 }104 105 // At this point, all descendants of `state.copy` have been finalized,106 // so we can be sure that `scope.canAutoFreeze` is accurate.107- if (immer.autoFreeze && scope.canAutoFreeze) {108- freeze(state.copy, false)107+ if (immer.autoFreeze && scope.canAutoFreeze_) {108+ freeze(state.copy_, false)109 }110 111- if (path && scope.patches) {112- generatePatches(state, path, scope.patches, scope.inversePatches!)111+ if (path && scope.patches_) {112+ generatePatches(state, path, scope.patches_, scope.inversePatches_!)113 }114 }115- return state.copy115+ return state.copy_116 }117 118 function finalizeTree(119 immer: Immer,120 root: Drafted,121 scope: ImmerScope,122 rootPath?: PatchPath123 ) {124- const state = root[DRAFT_STATE]124+ const state: ImmerState = root[DRAFT_STATE]125 if (state) {126 if (127- state.type === ProxyType.ES5Object ||128- state.type === ProxyType.ES5Array127+ state.type_ === ProxyType.ES5Object ||128+ state.type_ === ProxyType.ES5Array129 ) {130 // Create the final copy, with added keys and without deleted keys.131- state.copy = shallowCopy(state.draft, true)131+ state.copy_ = shallowCopy(state.draft_, true)132 }133- root = state.copy133+ root = state.copy_134 }135 each(root, (key, value) =>136 finalizeProperty(immer, scope, root, state, root, key, value, rootPath)137 )20 unmodified lines158 const path =159 rootPath &&160 isDraftProp &&161 !isSetMember && // Set objects are atomic since they have no keys.162- !has((rootState as Exclude<ImmerState, SetState>).assigned!, prop) // Skip deep patches for assigned keys.162+ !has((rootState as Exclude<ImmerState, SetState>).assigned_!, prop) // Skip deep patches for assigned keys.163 ? rootPath!.concat(prop)164 : undefined165 166 // Drafts owned by `scope` are finalized here.1 unmodified line168 set(parentValue, prop, childValue)169 170 // Drafts from another scope must prevent auto-freezing.171 if (isDraft(childValue)) {172- scope.canAutoFreeze = false172+ scope.canAutoFreeze_ = false173 }174 }175 // Unchanged draft properties are ignored.176- else if (isDraftProp && is(childValue, get(rootState.base, prop))) {176+ else if (isDraftProp && is(childValue, get(rootState.base_, prop))) {177 return178 }179 // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.180 // TODO: the recursion over here looks weird, shouldn't non-draft stuff have it's own recursion?10 unmodified lines191 grandChild,192 rootPath193 )194 )195- if (!scope.parent) maybeFreeze(immer, childValue)195+ if (!scope.parent_) maybeFreeze(immer, childValue)196 }197 198 if (isDraftProp && immer.onAssign && !isSetMember) {199 immer.onAssign(rootState, prop, childValue)8 unmodified linesmodified:src/immerClass.ts+15 added-15 removed
124 unmodified lines125 let result126 127 // Only plain objects, arrays, and "immerable classes" are drafted.128 if (isDraftable(base)) {129- const scope = ImmerScope.enter(this)129+ const scope = ImmerScope.enter_(this)130 const proxy = createProxy(this, base, undefined)131 let hasError = true132 try {133 result = recipe(proxy)134 hasError = false135 } finally {136 // finally instead of catch + rethrow better preserves original stack137- if (hasError) scope.revoke()138- else scope.leave()137+ if (hasError) scope.revoke_()138+ else scope.leave_()139 }140 if (typeof Promise !== "undefined" && result instanceof Promise) {141 return result.then(142 result => {143- scope.usePatches(patchListener)143+ scope.usePatches_(patchListener)144 return processResult(this, result, scope)145 },146 error => {147- scope.revoke()147+ scope.revoke_()148 throw error149 }150 )151 }152- scope.usePatches(patchListener)152+ scope.usePatches_(patchListener)153 return processResult(this, result, scope)154 } else {155 result = recipe(base)156 if (result === NOTHING) return undefined20 unmodified lines177 }178 179 createDraft<T extends Objectish>(base: T): Draft<T> {180 invariant(isDraftable(base), "First argument to `createDraft` must be a plain object, an array, or an immerable object") // prettier-ignore181- const scope = ImmerScope.enter(this)181+ const scope = ImmerScope.enter_(this)182 const proxy = createProxy(this, base, undefined)183- proxy[DRAFT_STATE].isManual = true184- scope.leave()183+ proxy[DRAFT_STATE].isManual_ = true184+ scope.leave_()185 return proxy as any186 }187 188 finishDraft<D extends Draft<any>>(189 draft: D,190 patchListener?: PatchListener191 ): D extends Draft<infer T> ? T : never {192 const state: ImmerState = draft && draft[DRAFT_STATE]193- invariant(state && state.isManual, "First argument to `finishDraft` must be a draft returned by `createDraft`") // prettier-ignore194- invariant(!state.finalized, "The given draft is already finalized") // prettier-ignore195- const {scope} = state196- scope.usePatches(patchListener)193+ invariant(state && state.isManual_, "First argument to `finishDraft` must be a draft returned by `createDraft`") // prettier-ignore194+ invariant(!state.finalized_, "The given draft is already finalized") // prettier-ignore195+ const {scope_: scope} = state196+ scope.usePatches_(patchListener)197 return processResult(this, undefined, scope)198 }199 200 /**51 unmodified lines252 : immer.useProxies253 ? createProxyProxy(value, parent)254 : createES5Proxy(value, parent)255 256- const scope = parent ? parent.scope : ImmerScope.current!257- scope.drafts.push(draft)256+ const scope = parent ? parent.scope_ : ImmerScope.current_!257+ scope.drafts_.push(draft)258 return draft259 }260 261 export function willFinalize(15 unmodified linesmodified:src/plugins.ts+24 added-24 removed
53 unmodified lines54 55 /** ES5 Plugin */56 57 interface ES5BaseState extends ImmerBaseState {58- finalizing: boolean59- assigned: {[key: string]: any}60- parent?: ImmerState61- revoked: boolean58+ finalizing_: boolean59+ assigned_: {[key: string]: any}60+ parent_?: ImmerState61+ revoked_: boolean62 }63 64 export interface ES5ObjectState extends ES5BaseState {65- type: ProxyType.ES5Object66- draft: Drafted<AnyObject, ES5ObjectState>67- base: AnyObject68- copy: AnyObject | null65+ type_: ProxyType.ES5Object66+ draft_: Drafted<AnyObject, ES5ObjectState>67+ base_: AnyObject68+ copy_: AnyObject | null69 }70 71 export interface ES5ArrayState extends ES5BaseState {72- type: ProxyType.ES5Array73- draft: Drafted<AnyObject, ES5ArrayState>74- base: AnyArray75- copy: AnyArray | null72+ type_: ProxyType.ES5Array73+ draft_: Drafted<AnyObject, ES5ArrayState>74+ base_: AnyArray75+ copy_: AnyArray | null76 }77 78 export function willFinalizeES5(79 scope: ImmerScope,16 unmodified lines96 97 /** Map / Set plugin */98 99 export interface MapState extends ImmerBaseState {100- type: ProxyType.Map101- copy: AnyMap | undefined102- assigned: Map<any, boolean> | undefined103- base: AnyMap104- revoked: boolean105- draft: Drafted<AnyMap, MapState>100+ type_: ProxyType.Map101+ copy_: AnyMap | undefined102+ assigned_: Map<any, boolean> | undefined103+ base_: AnyMap104+ revoked_: boolean105+ draft_: Drafted<AnyMap, MapState>106 }107 108 export interface SetState extends ImmerBaseState {109- type: ProxyType.Set110- copy: AnySet | undefined111- base: AnySet112- drafts: Map<any, Drafted> // maps the original value to the draft value in the new set113- revoked: boolean114- draft: Drafted<AnySet, SetState>109+ type_: ProxyType.Set110+ copy_: AnySet | undefined111+ base_: AnySet112+ drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set113+ revoked_: boolean114+ draft_: Drafted<AnySet, SetState>115 }116 117 export function proxyMap<T extends AnyMap>(target: T, parent?: ImmerState): T {118 return getPlugin("mapset").proxyMap(target, parent)22 unmodified linesmodified:src/proxy.ts+61 added-57 removed
18 unmodified lines19 } from "./internal"20 import invariant from "tiny-invariant"21 22 interface ProxyBaseState extends ImmerBaseState {23- assigned: {23+ assigned_: {24 [property: string]: boolean25 }26- parent?: ImmerState27- drafts?: {26+ parent_?: ImmerState27+ drafts_?: {28 [property: string]: Drafted<any, any>29 }30- revoke(): void30+ revoke_(): void31 }32 33 export interface ProxyObjectState extends ProxyBaseState {34- type: ProxyType.ProxyObject35- base: AnyObject36- copy: AnyObject | null37- draft: Drafted<AnyObject, ProxyObjectState>34+ type_: ProxyType.ProxyObject35+ base_: AnyObject36+ copy_: AnyObject | null37+ draft_: Drafted<AnyObject, ProxyObjectState>38 }39 40 export interface ProxyArrayState extends ProxyBaseState {41- type: ProxyType.ProxyArray42- base: AnyArray43- copy: AnyArray | null44- draft: Drafted<AnyArray, ProxyArrayState>41+ type_: ProxyType.ProxyArray42+ base_: AnyArray43+ copy_: AnyArray | null44+ draft_: Drafted<AnyArray, ProxyArrayState>45 }46 47 type ProxyState = ProxyObjectState | ProxyArrayState48 7 unmodified lines56 parent?: ImmerState57 ): Drafted<T, ProxyState> {58 const isArray = Array.isArray(base)59 const state: ProxyState = {60- type: isArray ? ProxyType.ProxyArray : (ProxyType.ProxyObject as any),60+ type_: isArray ? ProxyType.ProxyArray : (ProxyType.ProxyObject as any),61 // Track which produce call this is associated with.62- scope: parent ? parent.scope : ImmerScope.current!,62+ scope_: parent ? parent.scope_ : ImmerScope.current_!,63 // True for both shallow and deep changes.64- modified: false,64+ modified_: false,65 // Used during finalization.66- finalized: false,66+ finalized_: false,67 // Track which properties have been assigned (true) or deleted (false).68- assigned: {},68+ assigned_: {},69 // The parent draft state.70- parent,70+ parent_: parent,71 // The base state.72- base,72+ base_: base,73 // The base proxy.74- draft: null as any, // set below74+ draft_: null as any, // set below75 // Any property proxies.76- drafts: {},76+ drafts_: {},77 // The base copy with any updated values.78- copy: null,78+ copy_: null,79 // Called by the `produce` function.80- revoke: null as any,81- isManual: false80+ revoke_: null as any,81+ isManual_: false82 }83 84 // the traps must target something, a bit like the 'real' base.85 // but also, we need to be able to determine from the target what the relevant state is10 unmodified lines96 97 // TODO: optimization: might be faster, cheaper if we created a non-revocable proxy98 // and administrate revoking ourselves99 const {revoke, proxy} = Proxy.revocable(target, traps)100- state.draft = proxy as any101- state.revoke = revoke100+ state.draft_ = proxy as any101+ state.revoke_ = revoke102 return proxy as any103 }104 105 /**1 unmodified line107 */108 const objectTraps: ProxyHandler<ProxyState> = {109 get(state, prop) {110 if (prop === DRAFT_STATE) return state111- let {drafts} = state111+ let {drafts_: drafts} = state112 113 // Check for existing draft in unmodified state.114- if (!state.modified && has(drafts, prop)) {114+ if (!state.modified_ && has(drafts, prop)) {115 return drafts![prop as any]116 }117 118 const value = latest(state)[prop]119- if (state.finalized || !isDraftable(value)) {119+ if (state.finalized_ || !isDraftable(value)) {120 return value121 }122 123 // Check for existing draft in modified state.124- if (state.modified) {124+ if (state.modified_) {125 // Assigned values are never drafted. This catches any drafts we created, too.126- if (value !== peek(state.base, prop)) return value126+ if (value !== peek(state.base_, prop)) return value127 // Store drafts on the copy (when one exists).128 // @ts-ignore129- drafts = state.copy129+ drafts = state.copy_130 }131 132- return (drafts![prop as any] = createProxy(state.scope.immer, value, state))132+ return (drafts![prop as any] = createProxy(133+ state.scope_.immer_,134+ value,135+ state136+ ))137 },138 has(state, prop) {139 return prop in latest(state)140 },141 ownKeys(state) {142 return Reflect.ownKeys(latest(state))143 },144 set(state, prop: string /* strictly not, but helps TS */, value) {141- if (!state.modified) {142- const baseValue = peek(state.base, prop)145+ if (!state.modified_) {146+ const baseValue = peek(state.base_, prop)147 // Optimize based on value's truthiness. Truthy values are guaranteed to148 // never be undefined, so we can avoid the `in` operator. Lastly, truthy149 // values may be drafts, but falsy values are never drafts.150 const isUnchanged = value147- ? is(baseValue, value) || value === state.drafts![prop]148- : is(baseValue, value) && prop in state.base151+ ? is(baseValue, value) || value === state.drafts_![prop]152+ : is(baseValue, value) && prop in state.base_153 if (isUnchanged) return true154 prepareCopy(state)155 markChangedProxy(state)156 }153- state.assigned[prop] = true157+ state.assigned_[prop] = true158 // @ts-ignore155- state.copy![prop] = value159+ state.copy_![prop] = value160 return true161 },162 deleteProperty(state, prop: string) {163 // The `undefined` check is a fast path for pre-existing keys.160- if (peek(state.base, prop) !== undefined || prop in state.base) {161- state.assigned[prop] = false164+ if (peek(state.base_, prop) !== undefined || prop in state.base_) {165+ state.assigned_[prop] = false166 prepareCopy(state)167 markChangedProxy(state)164- } else if (state.assigned[prop]) {168+ } else if (state.assigned_[prop]) {169 // if an originally not assigned property was deleted166- delete state.assigned[prop]170+ delete state.assigned_[prop]171 }172 // @ts-ignore169- if (state.copy) delete state.copy[prop]173+ if (state.copy_) delete state.copy_[prop]174 return true175 },176 // Note: We never coerce `desc.value` into an Immer draft, because we can't make177 // the same guarantee in ES5 mode.2 unmodified lines180 const desc = Reflect.getOwnPropertyDescriptor(owner, prop)181 if (desc) {182 desc.writable = true183 desc.configurable =180- state.type !== ProxyType.ProxyArray || prop !== "length"184+ state.type_ !== ProxyType.ProxyArray || prop !== "length"185 }186 return desc187 },188 defineProperty() {189 invariant(false, "Object.defineProperty() cannot be used on an Immer draft") // prettier-ignore190 },191 getPrototypeOf(state) {188- return Object.getPrototypeOf(state.base)192+ return Object.getPrototypeOf(state.base_)193 },194 setPrototypeOf() {195 invariant(false, "Object.setPrototypeOf() cannot be used on an Immer draft") // prettier-ignore196 }34 unmodified lines231 return desc && desc.value232 }233 234 export function markChangedProxy(state: ImmerState) {231- if (!state.modified) {232- state.modified = true235+ if (!state.modified_) {236+ state.modified_ = true237 if (234- state.type === ProxyType.ProxyObject ||235- state.type === ProxyType.ProxyArray238+ state.type_ === ProxyType.ProxyObject ||239+ state.type_ === ProxyType.ProxyArray240 ) {237- const copy = (state.copy = shallowCopy(state.base))238- each(state.drafts!, (key, value) => {241+ const copy = (state.copy_ = shallowCopy(state.base_))242+ each(state.drafts_!, (key, value) => {243 // @ts-ignore244 copy[key] = value245 })242- state.drafts = undefined246+ state.drafts_ = undefined247 }248 245- if (state.parent) {246- markChangedProxy(state.parent)249+ if (state.parent_) {250+ markChangedProxy(state.parent_)251 }252 }253 }254 255 function prepareCopy(state: ProxyState) {252- if (!state.copy) {253- state.copy = shallowCopy(state.base)256+ if (!state.copy_) {257+ state.copy_ = shallowCopy(state.base_)258 }259 }modified:src/scope.ts+32 added-31 removed
4 unmodified lines5 ProxyType,6 Immer,7 DRAFT_STATE8 } from "./internal"9+import {ImmerState} from "./types-internal"10 11 /** Each scope represents a `produce` call. */12 // TODO: non-class?13 export class ImmerScope {13- static current?: ImmerScope14+ static current_?: ImmerScope15 15- patches?: Patch[]16- inversePatches?: Patch[]17- canAutoFreeze: boolean18- drafts: any[]19- parent?: ImmerScope20- patchListener?: PatchListener21- immer: Immer16+ patches_?: Patch[]17+ inversePatches_?: Patch[]18+ canAutoFreeze_: boolean19+ drafts_: any[]20+ parent_?: ImmerScope21+ patchListener_?: PatchListener22+ immer_: Immer23 24 constructor(parent: ImmerScope | undefined, immer: Immer) {24- this.drafts = []25- this.parent = parent26- this.immer = immer25+ this.drafts_ = []26+ this.parent_ = parent27+ this.immer_ = immer28 29 // Whenever the modified draft contains a draft from another scope, we30 // need to prevent auto-freezing so the unowned draft can be finalized.30- this.canAutoFreeze = true31+ this.canAutoFreeze_ = true32 }33 33- usePatches(patchListener?: PatchListener) {34+ usePatches_(patchListener?: PatchListener) {35 if (patchListener) {35- this.patches = []36- this.inversePatches = []37- this.patchListener = patchListener36+ this.patches_ = []37+ this.inversePatches_ = []38+ this.patchListener_ = patchListener39 }40 }41 41- revoke() {42- this.leave()43- this.drafts.forEach(revoke)42+ revoke_() {43+ this.leave_()44+ this.drafts_.forEach(revoke)45 // @ts-ignore45- this.drafts = null46+ this.drafts_ = null47 }48 48- leave() {49- if (this === ImmerScope.current) {50- ImmerScope.current = this.parent49+ leave_() {50+ if (this === ImmerScope.current_) {51+ ImmerScope.current_ = this.parent_52 }53 }54 54- static enter(immer: Immer) {55- const scope = new ImmerScope(ImmerScope.current, immer)56- ImmerScope.current = scope55+ static enter_(immer: Immer) {56+ const scope = new ImmerScope(ImmerScope.current_, immer)57+ ImmerScope.current_ = scope58 return scope59 }60 }61 62 function revoke(draft: Drafted) {62- const state = draft[DRAFT_STATE]63+ const state: ImmerState = draft[DRAFT_STATE]64 if (64- state.type === ProxyType.ProxyObject ||65- state.type === ProxyType.ProxyArray65+ state.type_ === ProxyType.ProxyObject ||66+ state.type_ === ProxyType.ProxyArray67 )67- state.revoke()68- else state.revoked = true68+ state.revoke_()69+ else state.revoked_ = true70 }modified:src/types-internal.ts+5 added-5 removed
31 unmodified lines32 Set33 }34 35 export interface ImmerBaseState {36- parent?: ImmerState37- scope: ImmerScope38- modified: boolean39- finalized: boolean40- isManual: boolean36+ parent_?: ImmerState37+ scope_: ImmerScope38+ modified_: boolean39+ finalized_: boolean40+ isManual_: boolean41 }42 43 export type ImmerState =44 | ProxyObjectState10 unmodified linesadded:notes.txt+51 added
1+Things to optimize2+3+[x] extract errors4+[x] don't enable all features by default5+[ ] "undefined" "object" prototype undefined ?6+[ ] kill hooks7+[x] _ postfix all members8+[ ] clean up finalize9+[ ] remove die10+11+Import size report for immer:12+┌───────────────────────┬───────────┬────────────┬───────────┐13+│ (index) │ just this │ cumulative │ increment │14+├───────────────────────┼───────────┼────────────┼───────────┤15+│ import * from 'immer' │ 6761 │ 0 │ 0 │16+│ produce │ 4048 │ 4048 │ 0 │17+│ enableES5 │ 4908 │ 4916 │ 868 │18+│ enableMapSet │ 5007 │ 5769 │ 853 │19+│ enablePatches │ 4836 │ 6544 │ 775 │20+└───────────────────────┴───────────┴────────────┴───────────┘21+(this report was generated by npmjs.com/package/import-size)22+23+---24+25+Extracted errors26+27+Import size report for immer:28+┌───────────────────────┬───────────┬────────────┬───────────┐29+│ (index) │ just this │ cumulative │ increment │30+├───────────────────────┼───────────┼────────────┼───────────┤31+│ import * from 'immer' │ 6271 │ 0 │ 0 │32+│ produce │ 3727 │ 3727 │ 0 │33+│ enableES5 │ 4516 │ 4524 │ 797 │34+│ enableMapSet │ 4589 │ 5348 │ 824 │35+│ enablePatches │ 4444 │ 6054 │ 706 │36+└───────────────────────┴───────────┴────────────┴───────────┘37+(this report was generated by npmjs.com/package/import-size)38+39+Mangled props:40+41+Import size report for immer:42+┌───────────────────────┬───────────┬────────────┬───────────┐43+│ (index) │ just this │ cumulative │ increment │44+├───────────────────────┼───────────┼────────────┼───────────┤45+│ import * from 'immer' │ 6132 │ 0 │ 0 │46+│ produce │ 3613 │ 3613 │ 0 │47+│ enableES5 │ 4420 │ 4428 │ 815 │48+│ enableMapSet │ 4439 │ 5227 │ 799 │49+│ enablePatches │ 4319 │ 5929 │ 702 │50+└───────────────────────┴───────────┴────────────┴───────────┘51+(this report was generated by npmjs.com/package/import-size)modified:package.json+1 added-1 removed
18 unmodified lines19 "test:build": "yarn build && yarn jest --config jest.config.build.js",20 "watch": "jest --watch",21 "coverage": "jest --coverage",22 "coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage",23- "build": "rimraf dist/ && tsdx build --name immer --format cjs,esm,umd && yarn build:flow",23+ "build": "rimraf dist/ && tsdx build --name immer --format esm,cjs,umd && yarn build:flow",24 "build:flow": "cpx 'src/immer.js.flow' dist -v",25 "publish-docs": "cd website && GIT_USER=mweststrate USE_SSH=true yarn run publish-gh-pages",26 "start": "cd website && yarn start",27 "test:size": "yarn build && yarn import-size --report . produce enableES5 enableMapSet enablePatches"57 unmodified linesmodified:tsdx.config.js+20 added-5 removed
1+const {terser} = require("rollup-plugin-terser")2+3 module.exports = {4 // This function will run for each entry/format/env combination5 rollup(config, options) {4- return options.format === "esm"5- ? {6- ...config7- }8- : config6+ if (options.format === "esm") {7+ config.plugins.push(8+ terser({9+ sourcemap: true,10+ module: true,11+ compress: {12+ hoist_funs: true,13+ passes: 314+ },15+ mangle: {16+ properties: {17+ regex: /_$/18+ }19+ }20+ })21+ )22+ }23+ return config24 }25 }