Skip to content
Myr

Flow: Add tests for Map and Set and fix base type

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Map and Set are Objects in Flow so {...} covers them.

authored by Björgvin Ragnarsson · committed by Björgvin Ragnarsson · parent 7d6b57b · Browse files · 2 files+42 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+42 added−2 removed

  • tests:+41 added−1 removed
  • other:+1 added−1 removed

2 files+42 added−2 removed

modified:__tests__/flow/flow.js.flow+41 added-1 removed
1// @flow2import produce, {3 enableMapSet,4 setAutoFreeze,5 setUseProxies,6 produce as produce2,7 applyPatches,8 Patch,9 original10} from "../../dist/index.js.flow"1112enableMapSet()13setAutoFreeze(true)14setUseProxies(true)1516// we really don't want this code to actually execute..
120 unmodified lines
137 })138}139140{139 const arr: Array<number> = [1];141 const arr: Array<number> = [1]142 produce(arr, draftState => {143 const a = original(draftState)144 if (a) {145 const b: number = a[0]
1 unmodified line
147 const c: string = a[0]148 }149 })150}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)188}
modified:src/types/index.js.flow+1 added-1 removed
6 unmodified lines
7}89export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void1011type Base = {...} | Array<any> | Map<any> | Set<any>11type Base = {...} | Array<any>12interface IProduce {13 /**14 * Immer takes a state, and runs a function against it.15 * That function can freely mutate the state, as it will create copies-on-write.
72 unmodified lines