Some final cleanup
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 12c38c6 · Browse files · 5 files·+5 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+5 added−17 removed
- other:+5 added−17 removed
Provenance
- Commit
82298d4- Tree
219dd4d- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
12c38c6
5 files changed+5 added−17 removed
modified:src/common.ts+1 added-2 removed
11 unmodified lines12 13 /** Use a class type for `nothing` so its type is unique */14 export class Nothing {15 // This lets us do `Exclude<T, Nothing>`16- // TODO: do this better, use unique symbol instead16 // @ts-ignore18- private _: any17+ private _!: unique symbol18 }19 20 const hasSymbol = typeof Symbol !== "undefined"21 export const hasMap = typeof Map !== "undefined"222 unmodified linesmodified:src/map.ts+2 added-4 removed
4 unmodified lines56789910111213 unmodified lines26272829313031323314 unmodified lines4849505154525354555636 unmodified lines939495969997989910010159 unmodified lines4 unmodified linesimport {assertUnrevoked} from "./es5"
export interface MapState extends ImmerBaseState { type: ProxyType.Map finalizing: boolean copy: AnyMap | undefined assigned: Map<any, boolean> | undefined base: AnyMap revoked: boolean13 unmodified lines parent, scope: parent ? parent.scope : ImmerScope.current!, modified: false, finalized: false, finalizing: false, copy: undefined, assigned: undefined, base: target, draft: this,14 unmodified lines const state = this[DRAFT_STATE] assertUnrevoked(state) if (latest(state).get(key) !== value) { prepareCopy(state) state.scope.immer.markChanged(state) // TODO: this needs to bubble up recursively correctly state.scope.immer.markChanged(state) state.assigned!.set(key, true) state.copy!.set(key, value) state.assigned!.set(key, true) }36 unmodified lines get(key: K): V { const state = this[DRAFT_STATE] assertUnrevoked(state) const value = latest(state).get(key) if (state.finalizing || state.finalized || !isDraftable(value)) { if (state.finalized || !isDraftable(value)) { return value } if (value !== state.base.get(key)) { return value // either already drafted or reassigned59 unmodified linesmodified:src/proxy.ts+2 added
92 unmodified lines93 target = [state] as any94 traps = arrayTraps95 }96 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 = revoke102 return proxy as any157 unmodified linesmodified:src/set.ts-2 removed
4 unmodified lines5 import {assertUnrevoked} from "./es5"6 7 export interface SetState extends ImmerBaseState {8 type: ProxyType.Set9- finalizing: boolean // TODO: kill?9 copy: AnySet | undefined10 base: AnySet11 drafts: Map<any, Drafted> // maps the original value to the draft value in the new set12 revoked: boolean13 unmodified lines26 parent,27 scope: parent ? parent.scope : ImmerScope.current!,28 modified: false,29 finalized: false,31- finalizing: false,30 copy: undefined,31 base: target,32 draft: this,33 drafts: new Map(),111 unmodified linesmodified:src/types.ts-9 removed
212 unmodified lines213 base: Base,214 recipe: (draft: D) => Return215 ): [Produced<Base, Return>, Patch[], Patch[]]216 }217-218-// Backward compatibility with --target es5219-// TODO: still needed?220-// declare global {221-// interface Set<T> {}222-// interface Map<K, V> {}223-// interface WeakSet<T> {}224-// interface WeakMap<K extends object, V> {}225-// }