scope.ts
This file
Path
src/scope.ts
67 lines · 1.4 KiB · TypeScript
Last changed by
Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
History of this fileTake it
Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 1why, one step back1import {Patch, PatchListener, Drafted, Immer, DRAFT_STATE} from "./internal"fix: Map and Set instantions won't work on certain environments, fixes #502Michel Weststratebefore adoption9f4711a
line 2why, one step back2import {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
lines 3–6why, one step back3 ImmerState,4 ProxyTypeProxyObject,5 ProxyTypeProxyArray6} from "./types-internal"feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 7–8why, one step back78/** Each scope represents a `produce` call. */use invariant -321 bytesMichel Weststratebefore adoptionac57da5
line 9why, one step back9// TODO: non-class?feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 10why, one step back10export class ImmerScope {Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
line 11why, one step back11 static current_?: ImmerScopefeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 12why, one step back12Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 13–19why, one step back13 patches_?: Patch[]14 inversePatches_?: Patch[]15 canAutoFreeze_: boolean16 drafts_: any[]17 parent_?: ImmerScope18 patchListener_?: PatchListener19 immer_: Immerfeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 20why, one step back20feat: rewrote Map and Set implementation, code base cleanupMichel Weststratebefore adoption1913fe8
line 21why, one step back21 constructor(parent: ImmerScope | undefined, immer: Immer) {Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 22–24why, one step back22 this.drafts_ = []23 this.parent_ = parent24 this.immer_ = immerfeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 25–27why, one step back2526 // Whenever the modified draft contains a draft from another scope, we27 // need to prevent auto-freezing so the unowned draft can be finalized.Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
line 28why, one step back28 this.canAutoFreeze_ = truefeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 29–30why, one step back29 }30Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
line 31why, one step back31 usePatches_(patchListener?: PatchListener) {feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 32why, one step back32 if (patchListener) {Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 33–35why, one step back33 this.patches_ = []34 this.inversePatches_ = []35 this.patchListener_ = patchListenerfeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 36–38why, one step back36 }37 }38Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 39–41why, one step back39 revoke_() {40 this.leave_()41 this.drafts_.forEach(revoke)feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 42why, one step back42 // @ts-ignoreMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
line 43why, one step back43 this.drafts_ = nullfeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 44–45why, one step back44 }45Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 46–48why, one step back46 leave_() {47 if (this === ImmerScope.current_) {48 ImmerScope.current_ = this.parent_feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 49–51why, one step back49 }50 }51Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 52–54why, one step back52 static enter_(immer: Immer) {53 const scope = new ImmerScope(ImmerScope.current_, immer)54 ImmerScope.current_ = scopefeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 55–58why, one step back55 return scope56 }57}58feat: rewrote Map and Set implementation, code base cleanupMichel Weststratebefore adoption1913fe8
line 59why, one step back59function revoke(draft: Drafted) {Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
line 60why, one step back60 const state: ImmerState = draft[DRAFT_STATE]feat: rewrote Map and Set implementation, code base cleanupMichel Weststratebefore adoption1913fe8
line 61why, one step back61 if (Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
lines 62–63why, one step back62 state.type_ === ProxyTypeProxyObject ||63 state.type_ === ProxyTypeProxyArrayfeat: rewrote Map and Set implementation, code base cleanupMichel Weststratebefore adoption1913fe8
line 64why, one step back64 )Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 65–66why, one step back65 state.revoke_()66 else state.revoked_ = truefeat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 67why, one step back67}