flow.js.flow
This file
Path
__tests__/flow/flow.js.flow
188 lines · 3.4 KiB
Last changed by
fix: Flow: Add tests for Map and Set and fix base typeMichel Weststratebefore adoption9022672
History of this fileTake it
The walk stopped after 200 commits: lines older than fbae585 point at it.
docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 1–2why, one step back1// @flow2import produce, {fix: Flow: Add tests for Map and Set and fix base typeMichel Weststratebefore adoption9022672
line 3why, one step back3 enableMapSet,docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 4–9why, one step back4 setAutoFreeze,5 setUseProxies,6 produce as produce2,7 applyPatches,8 Patch,9 originalfix: improve flow typesMichel Weststratebefore adoption427040c
line 10why, one step back10} from "../../dist/index.js.flow"docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 11why, one step back11fix: Flow: Add tests for Map and Set and fix base typeMichel Weststratebefore adoption9022672
line 12why, one step back12enableMapSet()docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 13–32why, one step back13setAutoFreeze(true)14setUseProxies(true)1516// we really don't want this code to actually execute..17const result = produce({x: 3}, draft => {18 draft.x = 41920 // $ExpectError21 console.log(draft.y)22})2324console.log(result.x)2526const result2 = produce({x: 3}, draft => {27 return {x: 4}28})2930console.log(result2.x)3132const f = produce(fix: improve flow typesMichel Weststratebefore adoption427040c
line 33why, one step back33 (draft): {| x: number |} => {docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 34–79why, one step back34 return {x: 4}35 }36)37f({x: 3})3839const f2 = produce((draft): void => {})40f2({x: 3})4142// $ExpectError43setAutoFreeze(3)4445// $ExpectError46console.log(result.y)4748// $ExpectError49produce()5051// $ExpectError52produce({x: 3})5354// $ExpectError55produce({x: 3}, [])5657{58 // curried & initial arg59 const f = produce(60 (state, increment: number): void => {61 state.x += increment62 },63 {x: 3}64 )6566 // $ExpectError Too few arguments67 f({x: 5})6869 // $ExpectError70 f({x: 5}, "test")7172 f({x: 5}, 3)7374 f(undefined, 3)75}7677{78 // curried f & no initial arg79 const f2 = produce(fix: improve flow typesMichel Weststratebefore adoption427040c
line 80why, one step back80 (state: {| x: number |}, increment: number): void => {docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 81–90why, one step back81 state.x += increment82 }83 )8485 f2({x: 5}, 3)8687 // $ExpectError88 f2(undefined, 3)89}90fix: improve flow typesMichel Weststratebefore adoption427040c
line 91why, one step back91type State = {| user: {| age: number |} |}docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 92why, one step back92{fix: improve flow typesMichel Weststratebefore adoption427040c
lines 93–105why, one step back93 declare function setState(updater: (State) => $Shape<State>): void94 // curried use with setState, infer type of draft95 setState(produce(draft => {96 if (draft.user.age === 10) {97 return98 }99 draft.user.age += 1100 // $ExpectError101 draft.user.name = "missing"102 }))103}104105{docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 106–140why, one step back106 // $ExpectError107 produce2({x: 3})108109 const result = produce2({x: 3}, draft => {110 draft.x = 4111112 // $ExpectError113 console.log(draft.y)114 })115}116117{118 let p: Patch[] = []119 produce(120 {},121 d => {},122 (patches, inverse) => {123 p = patches124 }125 )126 applyPatches({}, p)127}128129{130 produce({x: 3}, draftState => {131 let a = original(draftState)132 if (a) {133 a.x134 // $ExpectError135 a.y136 }137 })138}139140{fix: Flow: Add tests for Map and Set and fix base typeMichel Weststratebefore adoption9022672
line 141why, one step back141 const arr: Array<number> = [1]fix: improve flow typesMichel Weststratebefore adoption427040c
line 142why, one step back142 produce(arr, draftState => {docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 143–149why, one step back143 const a = original(draftState)144 if (a) {145 const b: number = a[0]146 // $ExpectError147 const c: string = a[0]148 }149 })fix: Flow: Add tests for Map and Set and fix base typeMichel Weststratebefore adoption9022672
lines 150–187why, one step back150}151152function testMap(state: Map<number, string>) {153 // normal154 state = produce(state, draft => {155 if (draft.has(1)) {156 return157 }158 // $ExpectError159 draft.set(1, 2)160 draft.set(1, "tada")161 })162 // curried, no initial state163 const f1 = produce(draft=> { draft.set(2, "ok") })164 state = f1(state)165 // curried, with initial state166 const f2 = produce(draft=> { draft.set(2, "ok") }, state)167 state = f2(state)168 state = f2(undefined)169}170171function testSet(state: Set<number>) {172 // normal173 state = produce(state, draft => {174 if (draft.has(1)) {175 return176 }177 // $ExpectError178 draft.add("me")179 draft.add(100)180 })181 // curried, no initial state182 const f1 = produce(draft => { draft.add(draft.size) })183 state = f1(state)184 // curried, with initial state185 const f2 = produce(draft => { draft.add(draft.size) }, state)186 state = f2(state)187 state = f2(undefined)docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 188why, one step back188}