{"size": 784, "ext": "js", "max_stars_repo_path": "src/enhancers/modeled-enhancer.js", "max_stars_repo_name": "eliseev-eag/react-redux-form", "max_stars_repo_stars_event_min_datetime": "2016-01-26T15:20:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T02:07:17.000Z", "max_issues_repo_path": "src/enhancers/modeled-enhancer.js", "max_issues_repo_name": "eliseev-eag/react-redux-form", "max_issues_repo_issues_event_min_datetime": "2016-01-26T15:09:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T22:15:54.000Z", "max_forks_repo_path": "src/enhancers/modeled-enhancer.js", "max_forks_repo_name": "davidkpiano/redux-simple-form", "max_forks_repo_forks_event_min_datetime": "2016-01-27T14:03:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T07:03:43.000Z"}
{"max_stars_count": 2329, "max_issues_count": 1034, "max_forks_count": 380, "avg_line_length": 29.037037037, "max_line_length": 87, "alphanum_fraction": 0.7308673469}
import modelReducer from '../reducers/model-reducer';
import NULL_ACTION from '../constants/null-action';

function createModelReducerEnhancer(modelReducerCreator = modelReducer, options = {}) {
  return function modelReducerEnhancer(reducer, model) {
    let initialState;
    try {
      initialState = reducer(undefined, NULL_ACTION);
    } catch (error) {
      initialState = null;
    }

    const _modelReducer = modelReducerCreator(model, initialState, options);

    return (state = initialState, action) => {
      const updatedState = _modelReducer(state, action);

      return reducer(updatedState, action);
    };
  };
}

const modelReducerEnhancer = createModelReducerEnhancer(modelReducer);

export { createModelReducerEnhancer };
export default modelReducerEnhancer;
