Flow WIP
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 3293adc · Browse files · 6 files·+76 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
6 files+76 added−17 removed
- tests:+32 added−0 removed
- other:+44 added−17 removed
Provenance
- Commit
8a572a4- Tree
96fe93d- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent
3293adc
6 files changed+76 added−17 removed
added:__tests__/flow/flow.js+32 added
1234567891011121314151617181920212223242526272829303132// @flowimport produce, {setAutoFreeze, setUseProxies} from "../../src/immer"
setAutoFreeze(true)setUseProxies(true)
const result = produce({x: 3}, draft => { draft.x = 4
// $ExpectError console.log(draft.y)})
console.log(result.x)
const f2 = produce(draft => {})f2({x: 3})
// $ExpectErrorsetAutoFreeze(3)
// $ExpectErrorconsole.log(result.y)
// $ExpectErrorproduce()
// $ExpectErrorproduce({x: 3})
// $ExpectErrorproduce({x: 3}, [])modified:src/immer.js.flow+28 added-15 removed
1-declare export function extendShallowObservable(target: any): any1+// @flow2 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.5 unmodified lines11 * @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>(15+declare function produce <S>(16+ recipe: (draftState: S, ...extraArgs: any[]) => void17+): (currentState: S, ...extraArgs: any[]) => S;18+declare function produce <S>(19 currentState: S,20 recipe: (draftState: S) => void18-): S21+) : S;22+function produce() {23+24+}25+26+declare export default produce27+28+// declare export function default <S>(29+// recipe: (draftState: S, ...extraArgs: any[]) => void30+// )=> (currentState: S, ...extraArgs: any[]) => S31+// declare export function default <S>(32+// currentState: S,33+// recipe: (draftState: S) => void34+// ) => S35 // 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[]) => S36+// declare export default <S, A, B, C>(37+// recipe: (draftState: S, a: A, b: B, c: C) => void38+// )=> (currentState: S, a: A, b: B, c: C) => S39+// declare export default <S, A, B>(40+// recipe: (draftState: S, a: A, b: B) => void41+// )=> (currentState: S, a: A, b: B) => S42+// declare export default <S, A>(43+// recipe: (draftState: S, a: A) => void44+// )=> (currentState: S) => S45 46 /**47 * Automatically freezes any state trees generated by immer.48 * This protects against accidental modifications of the state tree outside of an immer function.10 unmodified linesadded:.flowconfig+8 added
1+[ignore]2+.*/node_modules3+4+[include]5+__tests__/flow6+7+[options]8+suppress_comment= \\(.\\|\n\\)*\\$ExpectErrormodified:.travis.yml+1 added-1 removed
4 unmodified lines5678994 unmodified lines - NODE_ENV=TESTcache: directories: - "node_modules"script: yarn coverallsscript: yarn coveralls && yarn test:flowmodified:package.json+3 added-1 removed
9 unmodified lines10111213141516171853 unmodified lines7273747575767778799 unmodified lines "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$'", "test:flow": "yarn-or-npm flow check", "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 && cpx \"src/immer.{d.ts,js.flow}\" dist", "prettier": "prettier \"*/**/*.js\" --ignore-path ./.prettierignore --write", "prepublish": "yarn-or-npm run build"53 unmodified lines "^.+\\.jsx?$": "babel-jest" } }, "dependencies": { "cpx": "^1.5.0" "cpx": "^1.5.0", "flow-bin": "^0.64.0" }}modified:yarn.lock+4 added
1371 unmodified lines1372 resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"1373 dependencies:1374 locate-path "^2.0.0"1375 1376+flow-bin@^0.64.0:1377+ version "0.64.0"1378+ resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.64.0.tgz#ddd3fb3b183ab1ab35a5d5dec9caf5ebbcded167"1379+1380 for-in@^1.0.1:1381 version "1.0.2"1382 resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"1383 2155 unmodified lines