Skip to content
Myr

flow.js.flow

This file

Path

__tests__/flow/flow.js.flow

193 lines · 2.9 KiB

Last changed by

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

History of this file

Take it

The walk stopped after 200 commits: lines older than 07f5cc9 point at it.

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

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

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 2why, one step back
2import {

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 3–9why, one step back
3 produce,
4 enableMapSet,5 setAutoFreeze,6 produce as produce2,7 applyPatches,8 Patch,9 original

fix: Move index.js.flow from dist/ -> dist/cjs/ to match index.js (#1038)Björgvin Ragnarssonbefore adoptiona3b5603

line 10why, one step back
10} from "../../dist/cjs/index.js.flow"

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 11–16why, one step back
11
12enableMapSet()13setAutoFreeze(true)1415// we really don't want this code to actually execute..16const result = produce({x: 3}, draft => {

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

line 17why, one step back
17 draft.x = 4

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 18why, one step back
18

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 19–20why, one step back
19 // $ExpectError
20 console.log(draft.y)

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 21–25why, one step back
21})
2223console.log(result.x)2425const result2 = produce({x: 3}, draft => {

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

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

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 27–30why, one step back
27})
2829console.log(result2.x)30

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 31–33why, one step back
31const f = produce((draft): {|x: number|} => {
32 return {x: 4}33})

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 34–54why, one step back
34f({x: 3})
3536const f2 = produce((draft): void => {})37f2({x: 3})3839// $ExpectError40setAutoFreeze(3)4142// $ExpectError43console.log(result.y)4445// $ExpectError46produce()4748// $ExpectError49produce({x: 3})5051// $ExpectError52produce({x: 3}, [])5354{

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 55–61why, one step back
55 // curried & initial arg
56 const f = produce(57 (state, increment: number): void => {58 state.x += increment59 },60 {x: 3}61 )

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 62why, one step back
62

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 63–64why, one step back
63 // $ExpectError Too few arguments
64 f({x: 5})

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 65why, one step back
65

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 66–67why, one step back
66 // $ExpectError
67 f({x: 5}, "test")

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 68why, one step back
68

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

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

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 70why, one step back
70

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

line 71why, one step back
71 f(undefined, 3)

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 72–74why, one step back
72}
7374{

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 75–78why, one step back
75 // curried f & no initial arg
76 const f2 = produce((state: {|x: number|}, increment: number): void => {77 state.x += increment78 })

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 79why, one step back
79

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

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

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 81why, one step back
81

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 82–83why, one step back
82 // $ExpectError
83 f2(undefined, 3)

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 84–85why, one step back
84}
85

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

line 86why, one step back
86type State = {|user: {|age: number|}|}

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 87why, one step back
87{

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 88–99why, one step back
88 declare function setState(updater: (State) => $Shape<State>): void
89 // curried use with setState, infer type of draft90 setState(91 produce(draft => {92 if (draft.user.age === 10) {93 return94 }95 draft.user.age += 196 // $ExpectError97 draft.user.name = "missing"98 })99 )

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 100–102why, one step back
100}
101102{

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 103–104why, one step back
103 // $ExpectError
104 produce2({x: 3})

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 105why, one step back
105

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 106–107why, one step back
106 const result = produce2({x: 3}, draft => {
107 draft.x = 4

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 108why, one step back
108

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 109–111why, one step back
109 // $ExpectError
110 console.log(draft.y)111 })

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 112–114why, one step back
112}
113114{

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 115–123why, one step back
115 let p: Patch[] = []
116 produce(117 {},118 d => {},119 (patches, inverse) => {120 p = patches121 }122 )123 applyPatches({}, p)

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 124–126why, one step back
124}
125126{

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 127–134why, one step back
127 produce({x: 3}, draftState => {
128 let a = original(draftState)129 if (a) {130 a.x131 // $ExpectError132 a.y133 }134 })

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 135–137why, one step back
135}
136137{

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 138–146why, one step back
138 const arr: Array<number> = [1]
139 produce(arr, draftState => {140 const a = original(draftState)141 if (a) {142 const b: number = a[0]143 // $ExpectError144 const c: string = a[0]145 }146 })

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 147–149why, one step back
147}
148149function testMap(state: Map<number, string>) {

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 150–169why, one step back
150 // normal
151 state = produce(state, draft => {152 if (draft.has(1)) {153 return154 }155 // $ExpectError156 draft.set(1, 2)157 draft.set(1, "tada")158 })159 // curried, no initial state160 const f1 = produce(draft => {161 draft.set(2, "ok")162 })163 state = f1(state)164 // curried, with initial state165 const f2 = produce(draft => {166 draft.set(2, "ok")167 }, state)168 state = f2(state)169 state = f2(undefined)

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 170–172why, one step back
170}
171172function testSet(state: Set<number>) {

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 173–192why, one step back
173 // normal
174 state = produce(state, draft => {175 if (draft.has(1)) {176 return177 }178 // $ExpectError179 draft.add("me")180 draft.add(100)181 })182 // curried, no initial state183 const f1 = produce(draft => {184 draft.add(draft.size)185 })186 state = f1(state)187 // curried, with initial state188 const f2 = produce(draft => {189 draft.add(draft.size)190 }, state)191 state = f2(state)192 state = f2(undefined)

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 193why, one step back
193}