Skip to content

Commit

Permalink
Added test to verify #461
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 14, 2020
1 parent b658851 commit fdf4be6
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
101 changes: 101 additions & 0 deletions __tests__/redux.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {assert, _} from "spec.ts"
import produce, {
produce as produce2,
applyPatches,
Patch,
nothing,
Draft,
Immutable
} from "../src/"
import * as redux from "redux"

export interface State {
counter: number
}

export interface Action {
type: string
payload: number
}

export const initialState: State = {
counter: 0
}

/// =============== Actions

export function addToCounter(addNumber: number) {
return {
type: "ADD_TO_COUNTER",
payload: addNumber
}
}

export function subFromCounter(subNumber: number) {
return {
type: "SUB_FROM_COUNTER",
payload: subNumber
}
}

export const reduceCounterProducer = (
state: State = initialState,
action: Action
) =>
produce(state, draftState => {
switch (action.type) {
case "ADD_TO_COUNTER":
draftState.counter += action.payload
break
case "SUB_FROM_COUNTER":
draftState.counter -= action.payload
break
}
})

export const reduceCounterCurriedProducer = produce(
(draftState: Draft<State>, action: Action) => {
switch (action.type) {
case "ADD_TO_COUNTER":
draftState.counter += action.payload
break
case "SUB_FROM_COUNTER":
draftState.counter -= action.payload
break
}
},
initialState
)

/// =============== Reducers

export const reduce = redux.combineReducers({
counterReducer: reduceCounterProducer
})

export const curredReduce = redux.combineReducers({
counterReducer: reduceCounterCurriedProducer
})

// reducing the current state to get the next state!
// console.log(reduce(initialState, addToCounter(12));

// ================ store

export const store = redux.createStore(reduce)
export const curriedStore = redux.createStore(curredReduce)

it("#470 works with Redux combine reducers", () => {
assert(
store.getState().counterReducer,
_ as {
counter: number
}
)
assert(
curriedStore.getState().counterReducer,
_ as {
readonly counter: number
}
)
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"lodash.clonedeep": "^4.5.0",
"prettier": "1.19.1",
"pretty-quick": "^1.8.0",
"redux": "^4.0.5",
"regenerator-runtime": "^0.11.1",
"rimraf": "^2.6.2",
"rollup-plugin-typescript2": "^0.25.3",
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4711,7 +4711,7 @@ log-symbols@^2.2.0:
dependencies:
chalk "^2.0.1"

loose-envify@^1.0.0:
loose-envify@^1.0.0, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
Expand Down Expand Up @@ -6043,6 +6043,14 @@ realpath-native@^1.1.0:
dependencies:
util.promisify "^1.0.0"

redux@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==
dependencies:
loose-envify "^1.4.0"
symbol-observable "^1.2.0"

regenerate-unicode-properties@^8.0.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.0.2.tgz#7b38faa296252376d363558cfbda90c9ce709662"
Expand Down Expand Up @@ -6899,6 +6907,11 @@ svgo@^1.0.0:
unquote "~1.1.1"
util.promisify "~1.0.0"

symbol-observable@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==

symbol-tree@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
Expand Down

0 comments on commit fdf4be6

Please sign in to comment.