Skip to content
Myr

Some measurements fixes

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 9aec0fe · Browse files · 7 files+21 added−11 removed
This commit

State

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

Diff stats

7 files+21 added−11 removed

  • other:+21 added−11 removed

7 files+21 added−11 removed

modified:src/plugins/all.ts-1 removed
modified:src/plugins/es5.ts-1 removed
21 unmodified lines
22} from "../internal"2324type ES5State = ES5ArrayState | ES5ObjectState2526/*#__PURE__*/26export function enableES5() {27 function willFinalizeES5(28 scope: ImmerScope,29 result: any,
259 unmodified lines
modified:src/plugins/mapset.ts-1 removed
15 unmodified lines
16 loadPlugin,17 markChanged18} from "../internal"1920/*#__PURE__*/20export function enableMapSet() {21 /* istanbul ignore next */22 var extendStatics = function(d: any, b: any): any {23 extendStatics =
321 unmodified lines
modified:src/plugins/patches.ts-1 removed
19 unmodified lines
20 isMap,21 loadPlugin22} from "../internal"2324/*#__PURE__*/24export function enablePatches() {25 function generatePatches(26 state: ImmerState,27 basePath: PatchPath,
241 unmodified lines
modified:src/common.ts+15 added-1 removed
13 unmodified lines
14 hasMap15} from "./internal"1617/** Returns true if the given value is an Immer draft */18/*#__PURE__*/19export function isDraft(value: any): boolean {20 return !!value && !!value[DRAFT_STATE]21}2223/** Returns true if the given value can be drafted by Immer */24/*#__PURE__*/25export function isDraftable(value: any): boolean {26 if (!value) return false27 return (28 isPlainObject(value) ||
4 unmodified lines
33 isSet(value)34 )35}3637/*#__PURE__*/38export function isPlainObject(value: any): boolean {39 if (!value || typeof value !== "object") return false40 const proto = Object.getPrototypeOf(value)41 return !proto || proto === Object.prototype42}4344/** Get the underlying object that is represented by the given draft */45/*#__PURE__*/46export function original<T>(value: T): T | undefined47export function original(value: Drafted<any>): any {48 if (value && value[DRAFT_STATE]) {49 return value[DRAFT_STATE].base as any50 }51 // otherwise return undefined52}5354/*#__PURE__*/55export const ownKeys: (target: AnyObject) => PropertyKey[] =56 typeof Reflect !== "undefined" && Reflect.ownKeys57 ? Reflect.ownKeys58 : typeof Object.getOwnPropertySymbols !== "undefined"
14 unmodified lines
73 obj.forEach((entry: any, index: any) => iter(index, entry, obj))74 }75}7677/*#__PURE__*/78export function isEnumerable(base: AnyObject, prop: PropertyKey): boolean {79 const desc = Object.getOwnPropertyDescriptor(base, prop)80 return desc && desc.enumerable ? true : false81}8283/*#__PURE__*/84export function getArchtype(thing: any): Archtype {85 /* istanbul ignore next */86 if (!thing) die()87 if (thing[DRAFT_STATE]) {
18 unmodified lines
106 ? Archtype.Set107 : Archtype.Object108}109110/*#__PURE__*/111export function has(thing: any, prop: PropertyKey): boolean {112 return getArchtype(thing) === Archtype.Map113 ? thing.has(prop)114 : Object.prototype.hasOwnProperty.call(thing, prop)115}116117/*#__PURE__*/118export function get(thing: AnyMap | AnyObject, prop: PropertyKey): any {119 // @ts-ignore120 return getArchtype(thing) === Archtype.Map ? thing.get(prop) : thing[prop]121}122123/*#__PURE__*/124export function set(thing: any, propOrOldValue: PropertyKey, value: any) {125 switch (getArchtype(thing)) {126 case Archtype.Map:127 thing.set(propOrOldValue, value)
6 unmodified lines
134 thing[propOrOldValue] = value135 }136}137138/*#__PURE__*/139export function is(x: any, y: any): boolean {140 // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js141 if (x === y) {142 return x !== 0 || 1 / x === 1 / y
1 unmodified line
144 return x !== x && y !== y145 }146}147148/*#__PURE__*/149export function isMap(target: any): target is AnyMap {150 return hasMap && target instanceof Map151}152153/*#__PURE__*/154export function isSet(target: any): target is AnySet {155 return hasSet && target instanceof Set156}144157/*#__PURE__*/158export function latest(state: ImmerState): any {159 return state.copy || state.base160}161162/*#__PURE__*/163export function shallowCopy<T extends AnyObject | AnyArray>(164 base: T,165 invokeGetters?: boolean166): T
68 unmodified lines
modified:package.json+2 added-2 removed
modified:yarn.lock+4 added-4 removed
5836 unmodified lines
5837 dependencies:5838 pkg-dir "^4.2.0"5839 resolve-cwd "^3.0.0"58405841import-size@^1.0.1:5842 version "1.0.1"5843 resolved "https://registry.yarnpkg.com/import-size/-/import-size-1.0.1.tgz#b6de33fdbf82375ee17c5d9eddd74bf7d3f0b433"5844 integrity sha512-yWb3egI8xVKE2uqb1866P1lXW3AytSYrOzwfr1htqje/wvPFLCWuScmYO7gOmu6nsXU5Ucl6v2apuR0ycj/XUA==5841import-size@^1.0.2:5842 version "1.0.2"5843 resolved "https://registry.yarnpkg.com/import-size/-/import-size-1.0.2.tgz#2b4cf40ae75dc6b01bc8d850f26b9449748a3ee0"5844 integrity sha512-bGZTiThFEK9PETbhyC7Wu1r8rCIQ2BB9mh4HBbu7luVnrHHfKqrGCIoEVvpnQNoWKlLFfFD21LuULlHtBg5psg==5845 dependencies:5846 commander "^4.1.1"5847 import-cost "^1.9.0"5848
6846 unmodified lines