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 fileTake 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 back1// @flowMerge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 2why, one step back2import {chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 3–9why, one step back3 produce,4 enableMapSet,5 setAutoFreeze,6 produce as produce2,7 applyPatches,8 Patch,9 originalfix: Move index.js.flow from dist/ -> dist/cjs/ to match index.js (#1038)Björgvin Ragnarssonbefore adoptiona3b5603
line 10why, one step back10} from "../../dist/cjs/index.js.flow"chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 11–16why, one step back1112enableMapSet()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 back17 draft.x = 4chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 18why, one step back18chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 19–20why, one step back19 // $ExpectError20 console.log(draft.y)chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 21–25why, one step back21})2223console.log(result.x)2425const result2 = produce({x: 3}, draft => {chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
line 26why, one step back26 return {x: 4}chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 27–30why, one step back27})2829console.log(result2.x)30chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 31–33why, one step back31const f = produce((draft): {|x: number|} => {32 return {x: 4}33})chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 34–54why, one step back34f({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 back55 // curried & initial arg56 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 back62chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 63–64why, one step back63 // $ExpectError Too few arguments64 f({x: 5})chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 65why, one step back65chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 66–67why, one step back66 // $ExpectError67 f({x: 5}, "test")chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 68why, one step back68chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
line 69why, one step back69 f({x: 5}, 3)chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 70why, one step back70chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
line 71why, one step back71 f(undefined, 3)chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 72–74why, one step back72}7374{chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 75–78why, one step back75 // curried f & no initial arg76 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 back79chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
line 80why, one step back80 f2({x: 5}, 3)chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 81why, one step back81chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 82–83why, one step back82 // $ExpectError83 f2(undefined, 3)chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 84–85why, one step back84}85chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
line 86why, one step back86type State = {|user: {|age: number|}|}chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 87why, one step back87{chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 88–99why, one step back88 declare function setState(updater: (State) => $Shape<State>): void89 // 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 back100}101102{chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 103–104why, one step back103 // $ExpectError104 produce2({x: 3})chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 105why, one step back105chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 106–107why, one step back106 const result = produce2({x: 3}, draft => {107 draft.x = 4chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
line 108why, one step back108chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 109–111why, one step back109 // $ExpectError110 console.log(draft.y)111 })chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9
lines 112–114why, one step back112}113114{chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 115–123why, one step back115 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 back124}125126{chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 127–134why, one step back127 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 back135}136137{chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 138–146why, one step back138 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 back147}148149function testMap(state: Map<number, string>) {chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 150–169why, one step back150 // normal151 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 back170}171172function testSet(state: Set<number>) {chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 173–192why, one step back173 // normal174 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 back193}