All files reducerComponent.js

16.67% Statements 1/6
0% Branches 0/3
0% Functions 0/4
20% Lines 1/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27              1x                                      
import React from 'react';
 
// type State = Object *;
// type Reducer = EnumTagType -> (State | State -> State);
// type Config = { state :: State, reducer :: Reducer };
 
// reducerComponent :: Config -> React.Component -> React.Component
export const reducerComponent = (reducer, state) => Component => {
    class ReducerComponent extends React.Component {
        state = { ...state };
        // dispatch :: EnumTagType ~> ()
        dispatch = action => this.setState(reducer(action));
        render = () => React.createElement(Component, {
            ...this.props,
            dispatch: this.dispatch,
            state: this.state,
        });
    }
 
    ReducerComponent.displayName =
        `ReducerComponent(${Component.displayName || Component.name || 'Unknown'})`;
 
    return ReducerComponent;
};
 
export default reducerComponent;