Skip to content
Myr

scramble plugin names, -56

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 fdc78db · Browse files · 9 files+57 added−95 removed
This commit

State

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

Diff stats

9 files+57 added−95 removed

  • tests:+4 added−1 removed
  • other:+53 added−94 removed

9 files+57 added−95 removed

modified:__tests__/redux.ts+4 added-1 removed
modified:src/plugins/es5.ts+13 added-13 removed
23 unmodified lines
2425type ES5State = ES5ArrayState | ES5ObjectState2627export function enableES5() {28 function willFinalizeES5(28 function willFinalizeES5_(29 scope: ImmerScope,30 result: any,31 isReplaced: boolean32 ) {
16 unmodified lines
49 markChangesSweep(scope.drafts_)50 }51 }5253 function createES5Proxy<T>(53 function createES5Proxy_<T>(54 base: T,55 parent?: ImmerState56 ): Drafted<T, ES5ObjectState | ES5ArrayState> {57 const isArray = Array.isArray(base)
55 unmodified lines
113 assertUnrevoked(state)114 state.assigned_[prop] = true115 if (!state.modified_) {116 if (is(value, peek(latest(state), prop))) return117 markChangedES5(state)117 markChangedES5_(state)118 prepareCopy(state)119 }120 // @ts-ignore121 state.copy_![prop] = value122 }123124 function markChangedES5(state: ImmerState) {124 function markChangedES5_(state: ImmerState) {125 if (!state.modified_) {126 state.modified_ = true127 if (state.parent_) markChangedES5(state.parent_)127 if (state.parent_) markChangedES5_(state.parent_)128 }129 }130131 function prepareCopy(state: ES5State) {
48 unmodified lines
180 const state: ES5State = drafts[i][DRAFT_STATE]181 if (!state.modified_) {182 switch (state.type_) {183 case ProxyTypeES5Array:184 if (hasArrayChanges(state)) markChangedES5(state)184 if (hasArrayChanges(state)) markChangedES5_(state)185 break186 case ProxyTypeES5Object:187 if (hasObjectChanges(state)) markChangedES5(state)187 if (hasObjectChanges(state)) markChangedES5_(state)188 break189 }190 }191 }
14 unmodified lines
206 if ((key as any) === DRAFT_STATE) return207 // The `undefined` check is a fast path for pre-existing keys.208 if ((base_ as any)[key] === undefined && !has(base_, key)) {209 assigned_[key] = true210 markChangedES5(state)210 markChangedES5_(state)211 } else if (!assigned_[key]) {212 // Only untouched properties trigger recursion.213 markChangesRecursively(draft_[key])214 }
2 unmodified lines
217 each(base_, key => {218 // The `undefined` check is a fast path for pre-existing keys.219 if (draft_[key] === undefined && !has(draft_, key)) {220 assigned_[key] = false221 markChangedES5(state)221 markChangedES5_(state)222 }223 })224 } else if (type_ === ProxyTypeES5Array) {225 if (hasArrayChanges(state as ES5ArrayState)) {226 markChangedES5(state)226 markChangedES5_(state)227 assigned_.length = true228 }229230 if (draft_.length < base_.length) {
61 unmodified lines
292 return false293 }294295 loadPlugin("es5", {296 createES5Proxy,297 markChangedES5,298 willFinalizeES5296 createES5Proxy_,297 markChangedES5_,298 willFinalizeES5_299 })300}
modified:src/plugins/mapset.ts+3 added-3 removed
186 unmodified lines
187188 return DraftMap189 })(Map)190191 function proxyMap<T extends AnyMap>(target: T, parent?: ImmerState): T {191 function proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T {192 // @ts-ignore193 return new DraftMap(target, parent)194 }195
118 unmodified lines
314315 return DraftSet316 })(Set)317318 function proxySet<T extends AnySet>(target: T, parent?: ImmerState): T {318 function proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T {319 // @ts-ignore320 return new DraftSet(target, parent)321 }322
12 unmodified lines
335 })336 }337 }338339 loadPlugin("mapset", {proxyMap, proxySet})339 loadPlugin("mapset", {proxyMap_, proxySet_})340}
modified:src/plugins/patches.ts+3 added-3 removed
27 unmodified lines
28} from "../internal"29import invariant from "tiny-invariant"3031export function enablePatches() {32 function generatePatches(32 function generatePatches_(33 state: ImmerState,34 basePath: PatchPath,35 patches: Patch[],36 inversePatches: Patch[]
153 unmodified lines
190 i++191 })192 }193194 function applyPatches<T>(draft: T, patches: Patch[]): T {194 function applyPatches_<T>(draft: T, patches: Patch[]): T {195 patches.forEach(patch => {196 const {path, op} = patch197198 let base: any = draft
66 unmodified lines
265 for (const key in obj) cloned[key] = deepClonePatchValue(obj[key])266 return cloned267 }268269 loadPlugin("patches", {applyPatches, generatePatches})269 loadPlugin("patches", {applyPatches_, generatePatches_})270}
modified:src/finalize.ts+6 added-5 removed
5 unmodified lines
6 PatchPath,7 each,8 has,9 freeze,10 generatePatches,10 shallowCopy,11 ImmerState,12 isDraft,13 SetState,14 set,15 is,16 get,18 willFinalize,17 ProxyTypeES5Object,18 ProxyTypeES5Array,21 ProxyTypeSet19 ProxyTypeSet,20 getPlugin21} from "./internal"22import invariant from "tiny-invariant"2324export function processResult(result: any, scope: ImmerScope) {25 const baseDraft = scope.drafts_![0]26 const isReplaced = result !== undefined && result !== baseDraft28 willFinalize(scope, result, isReplaced)27 if (!scope.immer_.useProxies_)28 getPlugin("es5").willFinalizeES5_(scope, result, isReplaced)29 if (isReplaced) {30 if (baseDraft[DRAFT_STATE].modified_) {31 scope.revoke_()32 invariant(false, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.") // prettier-ignore
2 unmodified lines
35 // Finalize the result in case it contains (or is) a subset of the draft.36 result = finalize(scope, result)37 if (!scope.parent_) maybeFreeze(scope, result)38 }39 // TODO: move to plugin?40 if (scope.patches_) {41 scope.patches_.push({42 op: "replace",43 path: [],
50 unmodified lines
94 // everything inside is frozen, we can freeze here95 maybeFreeze(rootScope, result, false)96 // first time finalizing, let's create those patches97 if (path && rootScope.patches_) {97 generatePatches(98 getPlugin("patches").generatePatches_(99 state,100 path,101 rootScope.patches_,102 rootScope.inversePatches_!
50 unmodified lines
modified:src/immerClass.ts+8 added-20 removed
1import {2 createES5Proxy,3 willFinalizeES5,4 markChangedES5,2 IProduceWithPatches,3 IProduce,4 ImmerState,5 Drafted,
6 unmodified lines
12 DRAFT_STATE,13 Draft,14 PatchListener,15 isDraft,19 applyPatches,16 isMap,21 proxyMap,17 isSet,23 proxySet,18 markChangedProxy,19 createProxyProxy20} from "./internal"21import invariant from "tiny-invariant"22import {freeze} from "./common"23import {getPlugin} from "./plugins"2425declare const __DEV__: boolean26/* istanbul ignore next */27function verifyMinified() {}
170 unmodified lines
198 break199 }200 }201202 const applyPatchesImpl = getPlugin("patches").applyPatches_203 if (isDraft(base)) {204 // N.B: never hits if some patch a replacement, patches are never drafts209 return applyPatches(base, patches)205 return applyPatchesImpl(base, patches)206 }207 // Otherwise, produce a copy of the base state.208 return this.produce(base, (draft: Drafted) =>213 applyPatches(draft, patches.slice(i + 1))209 applyPatchesImpl(draft, patches.slice(i + 1))210 )211 }212}213
3 unmodified lines
217 parent?: ImmerState218): Drafted<T, ImmerState> {219 // precondition: createProxy should be guarded by isDraftable, so we know we can safely draft220 const draft: Drafted = isMap(value)225 ? proxyMap(value, parent)221 ? getPlugin("mapset").proxyMap_(value, parent)222 : isSet(value)227 ? proxySet(value, parent)223 ? getPlugin("mapset").proxySet_(value, parent)224 : immer.useProxies_225 ? createProxyProxy(value, parent)230 : createES5Proxy(value, parent)226 : getPlugin("es5").createES5Proxy_(value, parent)227228 const scope = parent ? parent.scope_ : ImmerScope.current_!229 scope.drafts_.push(draft)230 return draft231}232237export function willFinalize(238 scope: ImmerScope,239 thing: any,240 isReplaced: boolean241) {242 if (!scope.immer_.useProxies_) willFinalizeES5(scope, thing, isReplaced)243}244233export function markChanged(immer: Immer, state: ImmerState) {234 if (immer.useProxies_) {235 markChangedProxy(state)236 } else {249 markChangedES5(state)237 getPlugin("es5").markChangedES5_(state)238 }239}
modified:src/internal.ts+1 added-1 removed
modified:src/plugins.ts+15 added-47 removed
15 unmodified lines
1617/** Plugin utilities */18const plugins: {19 patches?: {20 generatePatches: typeof generatePatches21 applyPatches: typeof applyPatches20 generatePatches_(21 state: ImmerState,22 basePath: PatchPath,23 patches: Patch[],24 inversePatches: Patch[]25 ): void26 applyPatches_<T>(draft: T, patches: Patch[]): T27 }28 es5?: {24 willFinalizeES5: typeof willFinalizeES525 createES5Proxy: typeof createES5Proxy26 markChangedES5: typeof markChangedES529 willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void30 createES5Proxy_<T>(31 base: T,32 parent?: ImmerState33 ): Drafted<T, ES5ObjectState | ES5ArrayState>34 markChangedES5_(state: ImmerState): void35 }36 mapset?: {29 proxyMap: typeof proxyMap30 proxySet: typeof proxySet37 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T38 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T39 }40} = {}4142type Plugins = typeof plugins
42 unmodified lines
85 base_: AnyArray86 copy_: AnyArray | null87}8881export function willFinalizeES5(82 scope: ImmerScope,83 result: any,84 isReplaced: boolean85) {86 getPlugin("es5").willFinalizeES5(scope, result, isReplaced)87}8889export function createES5Proxy<T>(90 base: T,91 parent?: ImmerState92): Drafted<T, ES5ObjectState | ES5ArrayState> {93 return getPlugin("es5").createES5Proxy(base, parent)94}9596export function markChangedES5(state: ImmerState) {97 getPlugin("es5").markChangedES5(state)98}9989/** Map / Set plugin */9091export interface MapState extends ImmerBaseState {92 type_: typeof ProxyTypeMap
12 unmodified lines
105 revoked_: boolean106 draft_: Drafted<AnySet, SetState>107}108120export function proxyMap<T extends AnyMap>(target: T, parent?: ImmerState): T {121 return getPlugin("mapset").proxyMap(target, parent)122}123124export function proxySet<T extends AnySet>(target: T, parent?: ImmerState): T {125 return getPlugin("mapset").proxySet(target, parent)126}127109/** Patches plugin */110111export type PatchPath = (string | number)[]131132export function generatePatches(133 state: ImmerState,134 basePath: PatchPath,135 patches: Patch[],136 inversePatches: Patch[]137): void {138 getPlugin("patches").generatePatches(state, basePath, patches, inversePatches)139}140141export function applyPatches<T>(draft: T, patches: Patch[]): T {142 return getPlugin("patches").applyPatches(draft, patches)143}
modified:notes.txt+4 added-2 removed
6 unmodified lines
7[x] _ postfix all members8[x] clean up finalize9[x] remove die10[ ] own invariant11[ ] optimize enumerations11[ ] update docs12[ ] plugin tests13[ ] check if we can create more local vars15[ ] verify performance14[x] verify performance15[ ] kill ownKeys?16[x] kill enumerations17[ ] check todos18[ ] kill marchChangesSweep recursive if possible and no perf impact
83 unmodified lines
102│ enableMapSet │ 4071 │ 4847 │ 792 │103│ enablePatches │ 3936 │ 5528 │ 681 │104└───────────────────────┴───────────┴────────────┴───────────┘105(this report was generated by npmjs.com/package/import-size)106107Minimize plugin api's:108 3196