Added test to verify #461
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parent b658851 · Browse files · 3 files·+116 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+116 added−1 removed
- tests:+101 added−0 removed
- other:+15 added−1 removed
Provenance
- Commit
fdf4be6- Tree
351445e- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
b658851
3 files changed+116 added−1 removed
added:__tests__/redux.ts+101 added
1+import {assert, _} from "spec.ts"2+import produce, {3+ produce as produce2,4+ applyPatches,5+ Patch,6+ nothing,7+ Draft,8+ Immutable9+} from "../src/"10+import * as redux from "redux"11+12+export interface State {13+ counter: number14+}15+16+export interface Action {17+ type: string18+ payload: number19+}20+21+export const initialState: State = {22+ counter: 023+}24+25+/// =============== Actions26+27+export function addToCounter(addNumber: number) {28+ return {29+ type: "ADD_TO_COUNTER",30+ payload: addNumber31+ }32+}33+34+export function subFromCounter(subNumber: number) {35+ return {36+ type: "SUB_FROM_COUNTER",37+ payload: subNumber38+ }39+}40+41+export const reduceCounterProducer = (42+ state: State = initialState,43+ action: Action44+) =>45+ produce(state, draftState => {46+ switch (action.type) {47+ case "ADD_TO_COUNTER":48+ draftState.counter += action.payload49+ break50+ case "SUB_FROM_COUNTER":51+ draftState.counter -= action.payload52+ break53+ }54+ })55+56+export const reduceCounterCurriedProducer = produce(57+ (draftState: Draft<State>, action: Action) => {58+ switch (action.type) {59+ case "ADD_TO_COUNTER":60+ draftState.counter += action.payload61+ break62+ case "SUB_FROM_COUNTER":63+ draftState.counter -= action.payload64+ break65+ }66+ },67+ initialState68+)69+70+/// =============== Reducers71+72+export const reduce = redux.combineReducers({73+ counterReducer: reduceCounterProducer74+})75+76+export const curredReduce = redux.combineReducers({77+ counterReducer: reduceCounterCurriedProducer78+})79+80+// reducing the current state to get the next state!81+// console.log(reduce(initialState, addToCounter(12));82+83+// ================ store84+85+export const store = redux.createStore(reduce)86+export const curriedStore = redux.createStore(curredReduce)87+88+it("#470 works with Redux combine reducers", () => {89+ assert(90+ store.getState().counterReducer,91+ _ as {92+ counter: number93+ }94+ )95+ assert(96+ curriedStore.getState().counterReducer,97+ _ as {98+ readonly counter: number99+ }100+ )101+})modified:package.json+1 added
70 unmodified lines71727374757677787925 unmodified lines70 unmodified lines "lodash": "^4.17.4", "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", "seamless-immutable": "^7.1.3",25 unmodified linesmodified:yarn.lock+14 added-1 removed
4709 unmodified lines4710 integrity sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==4711 dependencies:4712 chalk "^2.0.1"4713 4714-loose-envify@^1.0.0:4714+loose-envify@^1.0.0, loose-envify@^1.4.0:4715 version "1.4.0"4716 resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"4717 integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==4718 dependencies:1323 unmodified lines6042 integrity sha512-wlgPA6cCIIg9gKz0fgAPjnzh4yR/LnXovwuo9hvyGvx3h8nX4+/iLZplfUWasXpqD8BdnGnP5njOFjkUwPzvjA==6043 dependencies:6044 util.promisify "^1.0.0"6045 6046+redux@^4.0.5:6047+ version "4.0.5"6048+ resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"6049+ integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==6050+ dependencies:6051+ loose-envify "^1.4.0"6052+ symbol-observable "^1.2.0"6053+6054 regenerate-unicode-properties@^8.0.2:6055 version "8.0.2"6056 resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.0.2.tgz#7b38faa296252376d363558cfbda90c9ce709662"6057 integrity sha512-SbA/iNrBUf6Pv2zU8Ekv1Qbhv92yxL4hiDa2siuxs4KKn4oOoMDHXjAf7+Nz9qinUQ46B1LcWEi/PhJfPWpZWQ==848 unmodified lines6906 stable "^0.1.8"6907 unquote "~1.1.1"6908 util.promisify "~1.0.0"6909 6910+symbol-observable@^1.2.0:6911+ version "1.2.0"6912+ resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"6913+ integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==6914+6915 symbol-tree@^3.2.2:6916 version "3.2.2"6917 resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"6918 integrity sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=467 unmodified lines