oo-redux-utils
Version:
Utility functions for Object-oriented Redux
21 lines (17 loc) • 775 B
Flow
// @flow
import type { ActionObject } from './Dispatch';
type Reducers<StateNamespacesType: { [string]: string }, StateType> = {
[$Keys<StateNamespacesType>]: (StateType | void, ActionObject) => StateType
};
export default function<StateNamespacesType: { [string]: string }, StateType>(
stateNamespaces: StateNamespacesType,
createNamespacedStateReducer: ($Keys<StateNamespacesType>) => (StateType | void, ActionObject) => StateType
): Reducers<StateNamespacesType, StateType> {
return Object.keys(stateNamespaces).reduce(
(
accumulatedReducers: Reducers<StateNamespacesType, StateType>,
stateNamespace: $Keys<StateNamespacesType>
) => ({ ...accumulatedReducers, [stateNamespace]: createNamespacedStateReducer(stateNamespace) }),
{}
);
}