UNPKG

typedux

Version:

Slightly adjusted Redux (awesome by default) for TS

36 lines 1.51 kB
import { applyMiddleware } from "redux"; import { ObservableStore } from "../../store/ObservableStore"; import { isFunction } from '../../util'; const Noop = (() => { }); /** * Create a new factory with the provided middlewares * to generate stores * * @param middlewares to install in the mock store * @returns {MockStoreFactory} */ function mockStoreFactory(middlewares = [], stateArgs = [], actionFactories = []) { return function (fromState, storeReducer = null, onStateChange = Noop, storeMixins = null) { // First calculate the store state if a function was provided let storeState = (isFunction(fromState)) ? fromState() : fromState; function makeStore() { const store = new ObservableStore(ObservableStore.makeSimpleReducers(...stateArgs), null, null, storeState); if (storeMixins) Object.assign(store, storeMixins); actionFactories.forEach(factory => factory.setStore(store)); store.subscribe(onStateChange); return store; } if (middlewares.length) { const addMiddleware = applyMiddleware(...middlewares)(makeStore); return addMiddleware(storeReducer, fromState); } else { return makeStore(); } }; } export function configureMockStoreFactory(middlewares = [], stateArgs = [], actionFactories = []) { return mockStoreFactory(middlewares, stateArgs, actionFactories); } //# sourceMappingURL=MockStore.js.map