Skip to content
Myr

flow.js.flow

This file

Path

__tests__/flow/flow.js.flow

118 lines · 1.9 KiB

Last changed by

Merge pull request #179 from RichieAHB/rahb/add-originalMichel Weststratebefore adoptionf8479c2

History of this file

Take it

fixed build attempt 2Michel Weststratebefore adoption7d2148c

line 1why, one step back
1// @flow

Merge pull request #179 from RichieAHB/rahb/add-originalMichel Weststratebefore adoptionf8479c2

line 2why, one step back
2import produce, {setAutoFreeze, setUseProxies, produce as produce2, applyPatches, Patch, original} from "../../src/immer"

fixed build attempt 2Michel Weststratebefore adoption7d2148c

lines 3–16why, one step back
3
4setAutoFreeze(true)5setUseProxies(true)67// we really don't want this code to actually execute..8const result = produce({x: 3}, draft => {9 draft.x = 41011 // $ExpectError12 console.log(draft.y)13})1415console.log(result.x)16

Merge pull request #127 from bugzpodder/masterMichel Weststratebefore adoption2546c5a

line 17why, one step back
17const result2 = produce({x: 3}, draft => {

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

line 18why, one step back
18 return {x: 4}

Merge pull request #127 from bugzpodder/masterMichel Weststratebefore adoption2546c5a

lines 19–22why, one step back
19})
2021console.log(result2.x)22

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

lines 23–26why, one step back
23const f = produce((draft): {x: number} => {
24 return {x: 4}25})26f({x: 3})

Merge pull request #127 from bugzpodder/masterMichel Weststratebefore adoption2546c5a

lines 27–28why, one step back
27
28const f2 = produce((draft): void => {})

fixed build attempt 2Michel Weststratebefore adoption7d2148c

lines 29–44why, one step back
29f2({x: 3})
3031// $ExpectError32setAutoFreeze(3)3334// $ExpectError35console.log(result.y)3637// $ExpectError38produce()3940// $ExpectError41produce({x: 3})4243// $ExpectError44produce({x: 3}, [])

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

lines 45–47why, one step back
45
46{47 // curried & initial arg

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

lines 48–53why, one step back
48 const f = produce(
49 (state, increment: number): void => {50 state.x += increment51 },52 {x: 3}53 )

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

lines 54–55why, one step back
54
55 // $ExpectError Too few arguments

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

line 56why, one step back
56 f({x: 5})

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

lines 57–58why, one step back
57
58 // $ExpectError

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

line 59why, one step back
59 f({x: 5}, "test")

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

line 60why, one step back
60

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

line 61why, one step back
61 f({x: 5}, 3)

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

lines 62–67why, one step back
62
63 f(undefined, 3)64}6566{67 // curried f & no initial arg

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

line 68why, one step back
68 const f2 = produce((state: {x: number}, increment: number): void => {

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

lines 69–71why, one step back
69 state.x += increment
70 })71

Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b

line 72why, one step back
72 f2({x: 5}, 3)

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

lines 73–75why, one step back
73
74 // $ExpectError75 f2(undefined, 3)

`produce` is now exported as both default and name export. Implements #136Michel Weststratebefore adoption05e3015

lines 76–87why, one step back
76}
7778{79 // $ExpectError80 produce2({x: 3})8182 const result = produce2({x: 3}, draft => {83 draft.x = 48485 // $ExpectError86 console.log(draft.y)87 })

Merge branch 'patches'Michel Weststratebefore adoption2513fb8

lines 88–95why, one step back
88}
8990{91 let p: Patch[] = []92 produce({ }, d=> {}, (patches, inverse) => {93 p = patches94 })95 applyPatches({}, p)

Merge pull request #179 from RichieAHB/rahb/add-originalMichel Weststratebefore adoptionf8479c2

lines 96–117why, one step back
96}
9798{99 produce({x: 3}, draftState => {100 let a = original(draftState)101 if (a) {102 a.x103 // $ExpectError104 a.y105 }106 })107}108109{110 produce([1], draftState => {111 const a = original(draftState);112 if (a) {113 const b: number = a[0];114 // $ExpectError115 const c: string = a[0];116 }117 })

Improved typings as suggested by #109. Improved typings of initialStateMichel Weststratebefore adoptioncf32c52

line 118why, one step back
118}