Added flow types, implements #34
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 9b61b6c · Browse files · 5 files·+150 added−50 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+150 added−50 removed
- other:+150 added−50 removed
Provenance
- Commit
737e556- Tree
53160f4- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent
9b61b6c
5 files changed+150 added−50 removed
added:src/immer.d.ts+43 added
12345678910111213141516171819202122232425262728293031323334353637383940414243/** * Immer takes a state, and runs a function against it. * That function can freely mutate the state, as it will create copies-on-write. * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned * * If only one argument is passed, this is interpreted as the recipe, and will create a curried function that will execute the recipe * any time it is called with a base state * * @param currentState - the state to start with * @param thunk - function that receives a proxy of the current state as first argument and which can be freely modified * @returns The next state: a new state, or the current state if nothing was modified */export default function<S = any>( currentState: S, recipe: (draftState: S) => void): S// curried invocationsexport default function<S = any, A = any, B = any, C = any>( recipe: (draftState: S, a: A, b: B, c: C) => void): (currentState: S, a: A, b: B, c: C) => Sexport default function<S = any, A = any, B = any>( recipe: (draftState: S, a: A, b: B) => void): (currentState: S, a: A, b: B) => Sexport default function<S = any, A = any>( recipe: (draftState: S, a: A) => void): (currentState: S) => Sexport default function<S = any>( recipe: (draftState: S, ...extraArgs: any[]) => void): (currentState: S, ...extraArgs: any[]) => S
/** * Automatically freezes any state trees generated by immer. * This protects against accidental modifications of the state tree outside of an immer function. * This comes with a performance impact, so it is recommended to disable this option in production. * It is by default enabled. */export function setAutoFreeze(autoFreeze: boolean): void
/** * Manually override whether proxies should be used. * By default done by using feature detection */export function setUseProxies(useProxies: boolean): voidadded:src/immer.js.flow+45 added
1+declare export function extendShallowObservable(target: any): any2+3+/**4+ * Immer takes a state, and runs a function against it.5+ * That function can freely mutate the state, as it will create copies-on-write.6+ * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned7+ *8+ * If only one argument is passed, this is interpreted as the recipe, and will create a curried function that will execute the recipe9+ * any time it is called with a base state10+ *11+ * @param currentState - the state to start with12+ * @param thunk - function that receives a proxy of the current state as first argument and which can be freely modified13+ * @returns The next state: a new state, or the current state if nothing was modified14+ */15+declare export default function<S>(16+ currentState: S,17+ recipe: (draftState: S) => void18+): S19+// curried invocations20+declare export default function<S, A, B, C>(21+ recipe: (draftState: S, a: A, b: B, c: C) => void22+): (currentState: S, a: A, b: B, c: C) => S23+declare export default function<S, A, B>(24+ recipe: (draftState: S, a: A, b: B) => void25+): (currentState: S, a: A, b: B) => S26+declare export default function<S, A>(27+ recipe: (draftState: S, a: A) => void28+): (currentState: S) => S29+declare export default function<S>(30+ recipe: (draftState: S, ...extraArgs: any[]) => void31+): (currentState: S, ...extraArgs: any[]) => S32+33+/**34+ * Automatically freezes any state trees generated by immer.35+ * This protects against accidental modifications of the state tree outside of an immer function.36+ * This comes with a performance impact, so it is recommended to disable this option in production.37+ * It is by default enabled.38+ */39+declare export function setAutoFreeze(autoFreeze: boolean): void40+41+/**42+ * Manually override whether proxies should be used.43+ * By default done by using feature detection44+ */45+declare export function setUseProxies(useProxies: boolean): voiddeleted:immer.d.ts-43 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243/** * Immer takes a state, and runs a function against it. * That function can freely mutate the state, as it will create copies-on-write. * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned * * If only one argument is passed, this is interpreted as the recipe, and will create a curried function that will execute the recipe * any time it is called with a base state * * @param currentState - the state to start with * @param thunk - function that receives a proxy of the current state as first argument and which can be freely modified * @returns The next state: a new state, or the current state if nothing was modified */export default function<S = any>( currentState: S, recipe: (draftState: S) => void): S// curried invocationsexport default function<S = any, A = any, B = any, C = any>( recipe: (draftState: S, a: A, b: B, c: C) => void): (currentState: S, a: A, b: B, c: C) => Sexport default function<S = any, A = any, B = any>( recipe: (draftState: S, a: A, b: B) => void): (currentState: S, a: A, b: B) => Sexport default function<S = any, A = any>( recipe: (draftState: S, a: A) => void): (currentState: S) => Sexport default function<S = any>( recipe: (draftState: S, ...extraArgs: any[]) => void): (currentState: S, ...extraArgs: any[]) => S
/** * Automatically freezes any state trees generated by immer. * This protects against accidental modifications of the state tree outside of an immer function. * This comes with a performance impact, so it is recommended to disable this option in production. * It is by default enabled. */export function setAutoFreeze(autoFreeze: boolean): void
/** * Manually override whether proxies should be used. * By default done by using feature detection */export function setUseProxies(useProxies: boolean): voidmodified:package.json+5 added-3 removed
5 unmodified lines678910101112131415151617181914 unmodified lines34353637383839404127 unmodified lines6970717273747576775 unmodified lines "umd:main": "dist/immer.umd.js", "module": "dist/immer.module.js", "jsnext:main": "dist/immer.module.js", "react-native": "dist/immer.module.js", "types": "./immer.d.ts", "types": "./dist/immer.d.ts", "scripts": { "test": "jest", "test:perf": "yarn-or-npm build && node --expose-gc node_modules/jest-cli/bin/jest.js --verbose --testRegex '__performance_tests__/.*?js$'", "coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", "build": "rimraf dist/ && cross-env NODE_ENV=production rollup -c", "build": "rimraf dist/ && cross-env NODE_ENV=production rollup -c && cpx \"src/immer.{d.ts,js.flow}\" dist", "prettier": "prettier \"*/**/*.js\" --ignore-path ./.prettierignore --write", "prepublish": "yarn-or-npm run build" }, "pre-commit": [14 unmodified lines "url": "https://github.com/mweststrate/immer/issues" }, "homepage": "https://github.com/mweststrate/immer#readme", "files": [ "immer.d.ts", "dist/" ], "devDependencies": { "@types/jest": "^22.0.0",27 unmodified lines "jest": { "transform": { "^.+\\.jsx?$": "babel-jest" } }, "dependencies": { "cpx": "^1.5.0" }}modified:yarn.lock+57 added-4 removed
134 unmodified lines135 array-equal@^1.0.0:136 version "1.0.0"137 resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93"138 139+array-filter@~0.0.0:140+ version "0.0.1"141+ resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-0.0.1.tgz#7da8cf2e26628ed732803581fd21f67cacd2eeec"142+143+array-map@~0.0.0:144+ version "0.0.0"145+ resolved "https://registry.yarnpkg.com/array-map/-/array-map-0.0.0.tgz#88a2bab73d1cf7bcd5c1b118a003f66f665fa662"146+147+array-reduce@~0.0.0:148+ version "0.0.0"149+ resolved "https://registry.yarnpkg.com/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b"150+151 array-unique@^0.2.1:152 version "0.2.1"153 resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53"154 573 unmodified lines728 lodash "^4.17.4"729 mkdirp "^0.5.1"730 source-map-support "^0.4.15"731 720-babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0:732+babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0, babel-runtime@^6.9.2:733 version "6.26.0"734 resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"735 dependencies:736 core-js "^2.4.0"176 unmodified lines913 ansi-styles "^3.1.0"914 escape-string-regexp "^1.0.5"915 supports-color "^4.0.0"916 905-chokidar@^1.6.1:917+chokidar@^1.6.0, chokidar@^1.6.1:918 version "1.7.0"919 resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"920 dependencies:921 anymatch "^1.3.0"108 unmodified lines1030 log-driver "^1.2.5"1031 minimist "^1.2.0"1032 request "^2.79.0"1033 1034+cpx@^1.5.0:1035+ version "1.5.0"1036+ resolved "https://registry.yarnpkg.com/cpx/-/cpx-1.5.0.tgz#185be018511d87270dedccc293171e37655ab88f"1037+ dependencies:1038+ babel-runtime "^6.9.2"1039+ chokidar "^1.6.0"1040+ duplexer "^0.1.1"1041+ glob "^7.0.5"1042+ glob2base "^0.0.12"1043+ minimatch "^3.0.2"1044+ mkdirp "^0.5.1"1045+ resolve "^1.1.7"1046+ safe-buffer "^5.0.1"1047+ shell-quote "^1.6.1"1048+ subarg "^1.0.0"1049+1050 cross-env@^5.1.3:1051 version "5.1.3"1052 resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.1.3.tgz#f8ae18faac87692b0a8b4d2f7000d4ec3a85dfd7"1053 dependencies:301 unmodified lines1355 randomatic "^1.1.3"1356 repeat-element "^1.1.2"1357 repeat-string "^1.5.2"1358 1359+find-index@^0.1.1:1360+ version "0.1.1"1361+ resolved "https://registry.yarnpkg.com/find-index/-/find-index-0.1.1.tgz#675d358b2ca3892d795a1ab47232f8b6e2e0dde4"1362+1363 find-up@^1.0.0:1364 version "1.1.2"1365 resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"1366 dependencies:115 unmodified lines1482 resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-2.0.0.tgz#81383d72db054fcccf5336daa902f182f6edbb28"1483 dependencies:1484 is-glob "^2.0.0"1485 1486+glob2base@^0.0.12:1487+ version "0.0.12"1488+ resolved "https://registry.yarnpkg.com/glob2base/-/glob2base-0.0.12.tgz#9d419b3e28f12e83a362164a277055922c9c0d56"1489+ dependencies:1490+ find-index "^0.1.1"1491+1492 glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:1493 version "7.1.2"1494 resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"1495 dependencies:876 unmodified lines2372 minimist@0.0.8:2373 version "0.0.8"2374 resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"2375 2338-minimist@^1.1.1, minimist@^1.2.0:2376+minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0:2377 version "1.2.0"2378 resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"2379 2380 minimist@~0.0.1:522 unmodified lines2903 resolve@1.1.7:2904 version "1.1.7"2905 resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"2906 2869-resolve@^1.1.6, resolve@^1.4.0:2907+resolve@^1.1.6, resolve@^1.1.7, resolve@^1.4.0:2908 version "1.5.0"2909 resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36"2910 dependencies:2911 path-parse "^1.0.5"111 unmodified lines3023 shebang-regex@^1.0.0:3024 version "1.0.0"3025 resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"3026 3027+shell-quote@^1.6.1:3028+ version "1.6.1"3029+ resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767"3030+ dependencies:3031+ array-filter "~0.0.0"3032+ array-map "~0.0.0"3033+ array-reduce "~0.0.0"3034+ jsonify "~0.0.0"3035+3036 shellwords@^0.1.0:3037 version "0.1.1"3038 resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"3039 151 unmodified lines3191 strip-json-comments@~2.0.1:3192 version "2.0.1"3193 resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"3194 3195+subarg@^1.0.0:3196+ version "1.0.0"3197+ resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2"3198+ dependencies:3199+ minimist "^1.1.0"3200+3201 supports-color@^2.0.0:3202 version "2.0.0"3203 resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"3204 330 unmodified lines