<commit_before>import { defaultConfig } from './constants';
import createFirestoreInstance from './createFirestoreInstance';

let firestoreInstance;

/**
 * @name reduxFirestore
 * @external
 * @description Redux store enhancer that accepts configuration options and adds
 * store.firestore. Enhancers are most commonly placed in redux's `compose` call
 * along side applyMiddleware.
 * @property {Object} firebaseInstance - Initiated firebase instance
 * @property {Object} config - Containing react-redux-firebase specific configuration
 * @return {Function} That accepts a component and returns a Component which
 * wraps the provided component (higher order component).
 * @return {Function} That enhances a redux store with store.firestore
 * @example <caption>Setup</caption>
 * import { createStore, compose } from 'redux'
 * import { reduxFirestore } from 'redux-firestore'
 * import firebase from 'firebase' // must be 4.5.0 or higher
 import 'firebase/firestore' // make sure you add this for firestore

 * // Redux Firestore Config
 * const config = {
 *   // here is where you place other config options
 * }

 * // initialize script from Firestore page
 * const fbConfg = {} // firebase config object
 * firebase.initializeApp(fbConfig)
 * firebase.firestore()
 *
 * // Add redux-firestore enhancer to store creation compose
 * // Note: In full projects this will often be within createStore.js or store.js
 const store = createStore(
     makeRootReducer(),
     initialState,
     compose(
       // pass firebase instance and config
       reduxFirestore(firebase, reduxConfig),
      //  applyMiddleware(...middleware),
      //  ...enhancers
     )
   )
 *
 * // Use Function later to create store
 * const store = createStoreWithFirestore(rootReducer, initialState)
 */
export default (firebaseInstance, otherConfig) => next =>
  (reducer, initialState, middleware) => {
    const store = next(reducer, initialState, middleware);

    const configs = { ...defaultConfig, ...otherConfig };

    firestoreInstance = createFirestoreInstance( // eslint-disable-line no-param-reassign
      firebaseInstance.firebase_ || firebaseInstance, // eslint-disable-line no-underscore-dangle, no-undef, max-len
      configs,
      store.dispatch // eslint-disable-line comma-dangle
    );

    store.firestore = firebaseInstance;

    return store;
  };

/**
 * @description Expose Firestore instance created internally. Useful for
 * integrations into external libraries such as redux-thunk and redux-observable.
 * @example <caption>redux-thunk integration</caption>
 * import { applyMiddleware, compose, createStore } from 'redux';
 * import thunk from 'redux-thunk';
 * import makeRootReducer from './reducers';<commit_msg>Set store.firestore to firestoreInstance. Fixes #19<commit_after>import { defaultConfig } from './constants';
import createFirestoreInstance from './createFirestoreInstance';

let firestoreInstance;

/**
 * @name reduxFirestore
 * @external
 * @description Redux store enhancer that accepts configuration options and adds
 * store.firestore. Enhancers are most commonly placed in redux's `compose` call
 * along side applyMiddleware.
 * @property {Object} firebaseInstance - Initiated firebase instance
 * @property {Object} config - Containing react-redux-firebase specific configuration
 * @return {Function} That accepts a component and returns a Component which
 * wraps the provided component (higher order component).
 * @return {Function} That enhances a redux store with store.firestore
 * @example <caption>Setup</caption>
 * import { createStore, compose } from 'redux'
 * import { reduxFirestore } from 'redux-firestore'
 * import firebase from 'firebase' // must be 4.5.0 or higher
 import 'firebase/firestore' // make sure you add this for firestore

 * // Redux Firestore Config
 * const config = {
 *   // here is where you place other config options
 * }

 * // initialize script from Firestore page
 * const fbConfg = {} // firebase config object
 * firebase.initializeApp(fbConfig)
 * firebase.firestore()
 *
 * // Add redux-firestore enhancer to store creation compose
 * // Note: In full projects this will often be within createStore.js or store.js
 const store = createStore(
     makeRootReducer(),
     initialState,
     compose(
       // pass firebase instance and config
       reduxFirestore(firebase, reduxConfig),
      //  applyMiddleware(...middleware),
      //  ...enhancers
     )
   )
 *
 * // Use Function later to create store
 * const store = createStoreWithFirestore(rootReducer, initialState)
 */
export default (firebaseInstance, otherConfig) => next =>
  (reducer, initialState, middleware) => {
    const store = next(reducer, initialState, middleware);

    const configs = { ...defaultConfig, ...otherConfig };

    firestoreInstance = createFirestoreInstance( // eslint-disable-line no-param-reassign
      firebaseInstance.firebase_ || firebaseInstance, // eslint-disable-line no-underscore-dangle, no-undef, max-len
      configs,
      store.dispatch // eslint-disable-line comma-dangle
    );

    store.firestore = firestoreInstance;

    return store;
  };

/**
 * @description Expose Firestore instance created internally. Useful for
 * integrations into external libraries such as redux-thunk and redux-observable.
 * @example <caption>redux-thunk integration</caption>
 * import { applyMiddleware, compose, createStore } from 'redux';
 * import thunk from 'redux-thunk';
 * import makeRootReducer from './reducers';
{'fraction_non_alphanumeric': 0.09936421435059037, 'fraction_numerical': 0.0014532243415077202, 'mean_word_length': 3.846830985915493, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '3342759', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1469, 'n_words': 490}