redux.ts
This file
Path
__tests__/redux.ts
234 lines · 4.3 KiB · TypeScript
Last changed by
feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
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
line 1why, one step back1import {assert, _} from "spec.ts"feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
line 2why, one step back2import produce, {Draft, enableES5, Immutable} from "../src/immer"docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 3why, one step back3import * as redux from "redux"Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 4–5why, one step back45enableES5()docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 6why, one step back6feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 7–11why, one step back7// Mutable Redux8{9 interface State {10 counter: number11 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 12why, one step back12feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 13–16why, one step back13 interface Action {14 type: string15 payload: number16 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 17why, one step back17feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 18–81why, one step back18 const initialState: State = {19 counter: 020 }2122 /// =============== Actions2324 const reduceCounterProducer = (state: State = initialState, action: Action) =>25 produce(state, draftState => {26 switch (action.type) {27 case "ADD_TO_COUNTER":28 draftState.counter += action.payload29 break30 case "SUB_FROM_COUNTER":31 draftState.counter -= action.payload32 break33 }34 })3536 const reduceCounterCurriedProducer = produce(37 (draftState: State, action: Action) => {38 switch (action.type) {39 case "ADD_TO_COUNTER":40 draftState.counter += action.payload41 break42 case "SUB_FROM_COUNTER":43 draftState.counter -= action.payload44 break45 }46 },47 initialState48 )4950 /// =============== Reducers5152 const reduce = redux.combineReducers({53 counterReducer: reduceCounterProducer54 })5556 const curredReduce = redux.combineReducers({57 counterReducer: reduceCounterCurriedProducer58 })5960 // reducing the current state to get the next state!61 // console.log(reduce(initialState, addToCounter(12));6263 // ================ store6465 const store = redux.createStore(reduce)66 const curriedStore = redux.createStore(curredReduce)6768 it("#470 works with Redux combine reducers", () => {69 assert(70 store.getState().counterReducer,71 _ as {72 counter: number73 }74 )75 assert(76 curriedStore.getState().counterReducer,77 _ as {78 counter: number79 }80 )81 })docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 82–83why, one step back82}83feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 84–89why, one step back84// Readonly Redux85{86 {87 interface State {88 readonly counter: number89 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 90why, one step back90feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 91–162why, one step back91 interface Action {92 readonly type: string93 readonly payload: number94 }9596 const initialState: State = {97 counter: 098 }99100 /// =============== Actions101102 const reduceCounterProducer = (103 state: State = initialState,104 action: Action105 ) =>106 produce(state, draftState => {107 switch (action.type) {108 case "ADD_TO_COUNTER":109 draftState.counter += action.payload110 break111 case "SUB_FROM_COUNTER":112 draftState.counter -= action.payload113 break114 }115 })116117 const reduceCounterCurriedProducer = produce(118 (draftState: Draft<State>, action: Action) => {119 switch (action.type) {120 case "ADD_TO_COUNTER":121 draftState.counter += action.payload122 break123 case "SUB_FROM_COUNTER":124 draftState.counter -= action.payload125 break126 }127 },128 initialState129 )130131 /// =============== Reducers132133 const reduce = redux.combineReducers({134 counterReducer: reduceCounterProducer135 })136137 const curredReduce = redux.combineReducers({138 counterReducer: reduceCounterCurriedProducer139 })140141 // reducing the current state to get the next state!142 // console.log(reduce(initialState, addToCounter(12));143144 // ================ store145146 const store = redux.createStore(reduce)147 const curriedStore = redux.createStore(curredReduce)148149 it("#470 works with Redux combine readonly reducers", () => {150 assert(151 store.getState().counterReducer,152 _ as {153 readonly counter: number154 }155 )156 assert(157 curriedStore.getState().counterReducer,158 _ as {159 readonly counter: number160 }161 )162 })docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 163–165why, one step back163 }164}165feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 166–168why, one step back166it("works with inferred curried reducer", () => {167 type State = {168 count: numberdocs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 169–170why, one step back169 }170feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 171–174why, one step back171 type Action = {172 type: "inc"173 count: number174 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 175why, one step back175feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 176–178why, one step back176 const defaultState = {177 count: 3178 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 179why, one step back179feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 180–186why, one step back180 const store = redux.createStore(181 produce((state: State, action: Action) => {182 if (action.type === "inc") state.count += action.count183 // @ts-expect-error184 state.count2185 }, defaultState)186 )docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 187why, one step back187feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 188–192why, one step back188 assert(store.getState(), _ as State)189 store.dispatch({190 type: "inc",191 count: 2192 })docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 193why, one step back193feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 194–198why, one step back194 store.dispatch({195 // @ts-expect-error196 type: "inc2",197 count: 2198 })docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 199–200why, one step back199})200feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 201–204why, one step back201it("works with inferred curried reducer - readonly", () => {202 type State = {203 readonly count: number204 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 205why, one step back205feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 206–209why, one step back206 type Action = {207 readonly type: "inc"208 readonly count: number209 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 210why, one step back210feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 211–213why, one step back211 const defaultState: State = {212 count: 3213 }docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 214why, one step back214feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 215–220why, one step back215 const store = redux.createStore(216 produce((state: Draft<State>, action: Action) => {217 if (action.type === "inc") state.count += action.count218 // @ts-expect-error219 state.count2220 }, defaultState)docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 221why, one step back221 )feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e
lines 222–233why, one step back222223 assert(store.getState(), _ as State)224 store.dispatch({225 type: "inc",226 count: 2227 })228229 store.dispatch({230 // @ts-expect-error231 type: "inc2",232 count: 2233 })docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 234why, one step back234})