Last active
December 1, 2018 09:54
-
-
Save prescottprue/329dc74dda512dd496b75e710707fc4d to your computer and use it in GitHub Desktop.
Setup of redux store for a Firebase application using cypress-firebase to test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, compose } from 'redux' | |
import firebase from 'firebase/app' | |
import 'firebase/auth' | |
import 'firebase/database' | |
import 'firebase/firestore' // make sure you add this for firestore | |
import { reactReduxFirebase } from 'react-redux-firebase' | |
import rootReducer from './reducer' | |
export default function configureStore(initialState, history) { | |
// Initialize firebase app if instance does not already exist | |
if (!window.fbInstance) { | |
// Initialize Firebase instance | |
firebase.initializeApp(fbConfig) | |
} | |
const createStoreWithMiddleware = compose( | |
// Pass firebase instance | |
reactReduxFirebase(window.fbInstance || firebase, { | |
userProfile: 'users', | |
enableLogging: false | |
}), | |
typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f | |
)(createStore) | |
// Create store instance | |
const store = createStoreWithMiddleware(rootReducer) | |
if (module.hot) { | |
// Enable Webpack hot module replacement for reducers | |
module.hot.accept('./reducer', () => { | |
const nextRootReducer = require('./reducer') | |
store.replaceReducer(nextRootReducer) | |
}) | |
} | |
return store | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment