Skip to content

Instantly share code, notes, and snippets.

@prescottprue
Last active December 1, 2018 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prescottprue/329dc74dda512dd496b75e710707fc4d to your computer and use it in GitHub Desktop.
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
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