Created
October 17, 2018 10:45
-
-
Save 0xMALVEE/49c0790ab07d1d54e540c466ff5cb0a8 to your computer and use it in GitHub Desktop.
This file contains 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, combineReducers, compose } from 'redux'; | |
import firebase from 'firebase'; | |
import 'firebase/firestore'; | |
import { reactReduxFirebase, firebaseReducer } from 'react-redux-firebase'; | |
import { reduxFirestore, firestoreReducer } from 'redux-firestore'; | |
// Reducers | |
import notifyReducer from './reducers/notifyReducer'; | |
import settingsReducer from './reducers/settingsReducer'; | |
const firebaseConfig = { | |
apiKey: 'AIzaSyAj2cQpepAuQjR_BzjiXikbV2zACUF5vsY', | |
authDomain: 'reactclientpanel-61f9d.firebaseapp.com', | |
databaseURL: 'https://reactclientpanel-61f9d.firebaseio.com', | |
projectId: 'reactclientpanel-61f9d', | |
storageBucket: 'reactclientpanel-61f9d.appspot.com', | |
messagingSenderId: '485531386544' | |
}; | |
// react-redux-firebase config | |
const rrfConfig = { | |
userProfile: 'users', | |
useFirestoreForProfile: true // Firestore for Profile instead of Realtime DB | |
}; | |
// Init firebase instance | |
firebase.initializeApp(firebaseConfig); | |
// Init firestore | |
const firestore = firebase.firestore(); | |
const settings = { timestampsInSnapshots: true }; | |
firestore.settings(settings); | |
// Add reactReduxFirebase enhancer when making store creator | |
const createStoreWithFirebase = compose( | |
reactReduxFirebase(firebase, rrfConfig), // firebase instance as first argument | |
reduxFirestore(firebase) | |
)(createStore); | |
const rootReducer = combineReducers({ | |
firebase: firebaseReducer, | |
firestore: firestoreReducer, | |
notify: notifyReducer, | |
settings: settingsReducer | |
}); | |
// Check for settings in localStorage | |
if (localStorage.getItem('settings') == null) { | |
// Default settings | |
const defaultSettings = { | |
disableBalanceOnAdd: true, | |
disableBalanceOnEdit: false, | |
allowRegistration: false | |
}; | |
// Set to localStorage | |
localStorage.setItem('settings', JSON.stringify(defaultSettings)); | |
} | |
// Create initial state | |
const initialState = { settings: JSON.parse(localStorage.getItem('settings')) }; | |
// Create store | |
const store = createStoreWithFirebase( | |
rootReducer, | |
initialState, | |
compose( | |
reactReduxFirebase(firebase), | |
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() | |
) | |
); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment