Skip to content
Myr

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

3 files+116 added−1 removed

added:__tests__/redux.ts+101 added
1import {assert, _} from "spec.ts"2import produce, {3 produce as produce2,4 applyPatches,5 Patch,6 nothing,7 Draft,8 Immutable9} from "../src/"10import * as redux from "redux"1112export interface State {13 counter: number14}1516export interface Action {17 type: string18 payload: number19}2021export const initialState: State = {22 counter: 023}2425/// =============== Actions2627export function addToCounter(addNumber: number) {28 return {29 type: "ADD_TO_COUNTER",30 payload: addNumber31 }32}3334export function subFromCounter(subNumber: number) {35 return {36 type: "SUB_FROM_COUNTER",37 payload: subNumber38 }39}4041export 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 })5556export 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)6970/// =============== Reducers7172export const reduce = redux.combineReducers({73 counterReducer: reduceCounterProducer74})7576export const curredReduce = redux.combineReducers({77 counterReducer: reduceCounterCurriedProducer78})7980// reducing the current state to get the next state!81// console.log(reduce(initialState, addToCounter(12));8283// ================ store8485export const store = redux.createStore(reduce)86export const curriedStore = redux.createStore(curredReduce)8788it("#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
modified:yarn.lock+14 added-1 removed
4709 unmodified lines
4710 integrity sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==4711 dependencies:4712 chalk "^2.0.1"47134714loose-envify@^1.0.0:4714loose-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 lines
6042 integrity sha512-wlgPA6cCIIg9gKz0fgAPjnzh4yR/LnXovwuo9hvyGvx3h8nX4+/iLZplfUWasXpqD8BdnGnP5njOFjkUwPzvjA==6043 dependencies:6044 util.promisify "^1.0.0"60456046redux@^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"60536054regenerate-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 lines
6906 stable "^0.1.8"6907 unquote "~1.1.1"6908 util.promisify "~1.0.0"69096910symbol-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==69146915symbol-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