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
Provenance
- Commit
737432a- Tree
d8ac3de- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
9aec0fe
7 files changed+21 added−11 removed
modified:src/plugins/all.ts-1 removed
1234556789import {enableES5} from "./es5"import {enableMapSet} from "./mapset"import {enablePatches} from "./patches"
/*#__PURE__*/export function enableAllPlugins() { enableES5() enableMapSet() enablePatches()}modified:src/plugins/es5.ts-1 removed
21 unmodified lines22 } from "../internal"23 24 type ES5State = ES5ArrayState | ES5ObjectState25 26-/*#__PURE__*/26 export function enableES5() {27 function willFinalizeES5(28 scope: ImmerScope,29 result: any,259 unmodified linesmodified:src/plugins/mapset.ts-1 removed
15 unmodified lines16 loadPlugin,17 markChanged18 } from "../internal"19 20-/*#__PURE__*/20 export function enableMapSet() {21 /* istanbul ignore next */22 var extendStatics = function(d: any, b: any): any {23 extendStatics =321 unmodified linesmodified:src/plugins/patches.ts-1 removed
19 unmodified lines20 isMap,21 loadPlugin22 } from "../internal"23 24-/*#__PURE__*/24 export function enablePatches() {25 function generatePatches(26 state: ImmerState,27 basePath: PatchPath,241 unmodified linesmodified:src/common.ts+15 added-1 removed
13 unmodified lines14 hasMap15 } from "./internal"16 17 /** Returns true if the given value is an Immer draft */18+/*#__PURE__*/19 export function isDraft(value: any): boolean {20 return !!value && !!value[DRAFT_STATE]21 }22 23 /** Returns true if the given value can be drafted by Immer */24+/*#__PURE__*/25 export function isDraftable(value: any): boolean {26 if (!value) return false27 return (28 isPlainObject(value) ||4 unmodified lines33 isSet(value)34 )35 }36 37+/*#__PURE__*/38 export function isPlainObject(value: any): boolean {39 if (!value || typeof value !== "object") return false40 const proto = Object.getPrototypeOf(value)41 return !proto || proto === Object.prototype42 }43 44 /** Get the underlying object that is represented by the given draft */45+/*#__PURE__*/46 export function original<T>(value: T): T | undefined47 export function original(value: Drafted<any>): any {48 if (value && value[DRAFT_STATE]) {49 return value[DRAFT_STATE].base as any50 }51 // otherwise return undefined52 }53 54+/*#__PURE__*/55 export const ownKeys: (target: AnyObject) => PropertyKey[] =56 typeof Reflect !== "undefined" && Reflect.ownKeys57 ? Reflect.ownKeys58 : typeof Object.getOwnPropertySymbols !== "undefined"14 unmodified lines73 obj.forEach((entry: any, index: any) => iter(index, entry, obj))74 }75 }76 77+/*#__PURE__*/78 export function isEnumerable(base: AnyObject, prop: PropertyKey): boolean {79 const desc = Object.getOwnPropertyDescriptor(base, prop)80 return desc && desc.enumerable ? true : false81 }82 83+/*#__PURE__*/84 export function getArchtype(thing: any): Archtype {85 /* istanbul ignore next */86 if (!thing) die()87 if (thing[DRAFT_STATE]) {18 unmodified lines106 ? Archtype.Set107 : Archtype.Object108 }109 110+/*#__PURE__*/111 export function has(thing: any, prop: PropertyKey): boolean {112 return getArchtype(thing) === Archtype.Map113 ? thing.has(prop)114 : Object.prototype.hasOwnProperty.call(thing, prop)115 }116 117+/*#__PURE__*/118 export function get(thing: AnyMap | AnyObject, prop: PropertyKey): any {119 // @ts-ignore120 return getArchtype(thing) === Archtype.Map ? thing.get(prop) : thing[prop]121 }122 123+/*#__PURE__*/124 export function set(thing: any, propOrOldValue: PropertyKey, value: any) {125 switch (getArchtype(thing)) {126 case Archtype.Map:127 thing.set(propOrOldValue, value)6 unmodified lines134 thing[propOrOldValue] = value135 }136 }137 138+/*#__PURE__*/139 export 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 / y1 unmodified line144 return x !== x && y !== y145 }146 }147 148+/*#__PURE__*/149 export function isMap(target: any): target is AnyMap {150 return hasMap && target instanceof Map151 }152 153+/*#__PURE__*/154 export function isSet(target: any): target is AnySet {155 return hasSet && target instanceof Set156 }144-157+/*#__PURE__*/158 export function latest(state: ImmerState): any {159 return state.copy || state.base160 }161 162+/*#__PURE__*/163 export function shallowCopy<T extends AnyObject | AnyArray>(164 base: T,165 invokeGetters?: boolean166 ): T68 unmodified linesmodified:package.json+2 added-2 removed
22 unmodified lines2324252627272829303130 unmodified lines6263646566666768697013 unmodified lines22 unmodified lines "build": "rimraf dist/ && tsdx build --name immer --format cjs,esm,umd && yarn build:flow", "build:flow": "cpx 'src/immer.js.flow' dist -v", "publish-docs": "cd website && GIT_USER=mweststrate USE_SSH=true yarn run publish-gh-pages", "start": "cd website && yarn start", "test:size": "yarn import-size --report . produce enableES5 enableMapSet enablePatches" "test:size": "yarn build && yarn import-size --report . produce enableES5 enableMapSet enablePatches" }, "husky": { "hooks": { "pre-commit": "pretty-quick --staged"30 unmodified lines "deep-freeze": "^0.0.1", "flow-bin": "^0.68.0", "husky": "^1.2.0", "immutable": "^3.8.2", "import-size": "^1.0.1", "import-size": "^1.0.2", "jest": "^25.1.0", "lodash": "^4.17.4", "lodash.clonedeep": "^4.5.0", "prettier": "1.19.1",13 unmodified linesmodified:yarn.lock+4 added-4 removed
5836 unmodified lines5837 dependencies:5838 pkg-dir "^4.2.0"5839 resolve-cwd "^3.0.0"5840 5841-import-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==5841+import-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