From 667e18bc8116ed2b2275788fa90fecdd1edc36b2 Mon Sep 17 00:00:00 2001 From: Aranda Morrison Date: Thu, 23 Mar 2017 14:49:08 +0800 Subject: [PATCH] Attempt integration with react-redux-firebase. Gets `state.setIn is not a function` errors during START after a rehydrate. --- package.json | 5 ++++- src/modules/counter/CounterViewContainer.js | 7 ++++++- src/redux/reducer.js | 2 ++ src/redux/store.js | 23 ++++++++++++++++++--- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7894e824..43ba634a 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,9 @@ }, "jest": { "preset": "react-native", - "setupFiles": ["/test/setup.js"], + "setupFiles": [ + "/test/setup.js" + ], "transformIgnorePatterns": [ "node_modules/(?!(jest-)?react-native|react-navigation)" ] @@ -45,6 +47,7 @@ "react-native-vector-icons": "^4.0.0", "react-navigation": "^1.0.0-beta.6", "react-redux": "^4.4.5", + "react-redux-firebase": "prescottprue/react-redux-firebase#react-native", "redux": "^3.4.0", "redux-logger": "^2.6.1", "redux-loop-symbol-ponyfill": "^2.2.0", diff --git a/src/modules/counter/CounterViewContainer.js b/src/modules/counter/CounterViewContainer.js index a1c9fe65..4d848d49 100644 --- a/src/modules/counter/CounterViewContainer.js +++ b/src/modules/counter/CounterViewContainer.js @@ -4,6 +4,11 @@ import CounterView from './CounterView'; import {NavigationActions} from 'react-navigation'; import * as CounterStateActions from '../counter/CounterState'; +import {firebaseConnect, dataToJS} from 'react-redux-firebase'; +const CounterViewWithFirebase = firebaseConnect([ + '/counter' +])(CounterView) + export default connect( state => ({ counter: state.counter.value, @@ -15,4 +20,4 @@ export default connect( counterStateActions: bindActionCreators(CounterStateActions, dispatch) }; } -)(CounterView); +)(CounterViewWithFirebase); diff --git a/src/redux/reducer.js b/src/redux/reducer.js index 2170e4ef..a984839a 100644 --- a/src/redux/reducer.js +++ b/src/redux/reducer.js @@ -1,9 +1,11 @@ import {loop, combineReducers} from 'redux-loop-symbol-ponyfill'; +import {firebaseStateReducer} from 'react-redux-firebase' import NavigatorStateReducer from '../modules/navigator/NavigatorState'; import CounterStateReducer from '../modules/counter/CounterState'; import SessionStateReducer, {RESET_STATE} from '../modules/session/SessionState'; const reducers = { + firebase: firebaseStateReducer, // Counter sample app state. This can be removed in a live application counter: CounterStateReducer, diff --git a/src/redux/store.js b/src/redux/store.js index f8a8afc7..7f200424 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -1,5 +1,6 @@ import {applyMiddleware, createStore, compose} from 'redux'; import * as reduxLoop from 'redux-loop-symbol-ponyfill'; +import ReactNative from 'react-native'; import middleware from './middleware'; import reducer from './reducer'; @@ -18,11 +19,27 @@ const composeEnhancers = (__DEV__ && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ const enhancer = composeEnhancers(...enhancers); -// create the store +// Firebase config +const firebaseConfig = { + apiKey: '', + authDomain: '', + databaseURL: '' +}; + +import { reactReduxFirebase } from 'react-redux-firebase'; const store = createStore( reducer, - null, - enhancer + { firebase: { authError: null } }, + compose( + reactReduxFirebase( + firebaseConfig, { + userProfile: 'users', + enableRedirectHandling: false, + enableLogging: true, + rn: ReactNative + }), + enhancer, + ) ); export default store;