<commit_before>import React from 'react';
import _ from 'lodash';
import { connect as reduxConnect } from 'react-redux';
import reduxOkapi from 'redux-okapi';
import * as localstate from './localstate';
import * as okapi from './okapi';
import Wrapping from './ComponentWrapping';


class Wrapper extends React.Component {
  render() {
    return React.createElement(this.props.wrapped);
  }
};


// TODO: This should move to provider or store somehow
//
// Current keys:
//   addReducer(<state key>, <reducer function>)
let config = {};
export const init = newConfig => Object.assign(config, newConfig);

export const connect = (Component, module) => {
  if (!config.addReducer) {
    throw new Error('stripes-connect not configured---please call init() first');
  }
  const addReducer = config.addReducer;
  const manifest = Component.manifest;
  const resources = Object.keys(manifest);

  _.forOwn(manifest, (query, resource) => {
    if (query.remote) {
      addReducer(resource, okapi.reducerFor(resource, module));
    } else {
      addReducer(`${module}-${resource}`, localstate.reducerFor(resource, module));
    }
  });

  const mapStateToProps = (state) => {
    return resources.reduce((result, resource) => {
      const query = manifest[resource];
      if (query.remote) {
        result[resource] = _.get(state, [resource], null);
      } else {
        result[resource] = _.get(state, [`${module}-${resource}`], null);
      }
      return result;
    }, {});
  }

  const mapDispatchToProps = (dispatch) => {
    return {
      mutator: resources.reduce((result, resource) => {
        const query = manifest[resource];
        if (query.remote) {
          result[resource] = okapi.mutatorFor(resource, module, dispatch);
        } else {
          result[resource] = localstate.mutatorFor(resource, module, dispatch);
        }
        return result;
      }, {}),
      refreshRemote: (params) => {
        _.forOwn(manifest, (query, resource) => {
          if (query.remote) { 
            let overrides = {};
            if (query.suffix && query.suffix.startsWith(":")) {
              let suffix = query.suffix.substring(1);
              overrides = { suffix : "/"+params[suffix]};
            }                       
            dispatch(reduxOkapi.actions.fetch(resource,overrides));
          }
        });
      }
    };
  }
  let WrappedComponent = Wrapping(Component);
  const connectedComponent = reduxConnect(mapStateToProps, mapDispatchToProps)(WrappedComponent);
  return connectedComponent;
};

<commit_msg>Removes obsolete code<commit_after>import React from 'react';
import _ from 'lodash';
import { connect as reduxConnect } from 'react-redux';
import reduxOkapi from 'redux-okapi';
import * as localstate from './localstate';
import * as okapi from './okapi';
import Wrapping from './ComponentWrapping';


// TODO: This should move to provider or store somehow
//
// Current keys:
//   addReducer(<state key>, <reducer function>)
let config = {};
export const init = newConfig => Object.assign(config, newConfig);

export const connect = (Component, module) => {
  if (!config.addReducer) {
    throw new Error('stripes-connect not configured---please call init() first');
  }
  const addReducer = config.addReducer;
  const manifest = Component.manifest;
  const resources = Object.keys(manifest);

  _.forOwn(manifest, (query, resource) => {
    if (query.remote) {
      addReducer(resource, okapi.reducerFor(resource, module));
    } else {
      addReducer(`${module}-${resource}`, localstate.reducerFor(resource, module));
    }
  });

  const mapStateToProps = (state) => {
    return resources.reduce((result, resource) => {
      const query = manifest[resource];
      if (query.remote) {
        result[resource] = _.get(state, [resource], null);
      } else {
        result[resource] = _.get(state, [`${module}-${resource}`], null);
      }
      return result;
    }, {});
  }

  const mapDispatchToProps = (dispatch) => {
    return {
      mutator: resources.reduce((result, resource) => {
        const query = manifest[resource];
        if (query.remote) {
          result[resource] = okapi.mutatorFor(resource, module, dispatch);
        } else {
          result[resource] = localstate.mutatorFor(resource, module, dispatch);
        }
        return result;
      }, {}),
      refreshRemote: (params) => {
        _.forOwn(manifest, (query, resource) => {
          if (query.remote) { 
            let overrides = {};
            if (query.suffix && query.suffix.startsWith(":")) {
              let suffix = query.suffix.substring(1);
              overrides = { suffix : "/"+params[suffix]};
            }                       
            dispatch(reduxOkapi.actions.fetch(resource,overrides));
          }
        });
      }
    };
  }
  let WrappedComponent = Wrapping(Component);
  const connectedComponent = reduxConnect(mapStateToProps, mapDispatchToProps)(WrappedComponent);
  return connectedComponent;
};


{'fraction_non_alphanumeric': 0.1406813627254509, 'fraction_numerical': 0.0004008016032064128, 'mean_word_length': 2.821592649310873, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1751581', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1410, 'n_words': 335}