-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated presence demo with redux-persist for quicker navigation
- Loading branch information
Showing
9 changed files
with
192 additions
and
29 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,66 @@ | ||
import { applyMiddleware, combineReducers, createStore } from 'redux' | ||
import { bindActionCreators } from 'redux' | ||
import thunk from 'redux-thunk' | ||
import { bindActionCreatorsToStore } from 'redux-module-builder'; | ||
import { bindActionCreators, compose } from 'redux' | ||
import thunkMiddleware from 'redux-thunk' | ||
import {persistStore, autoRehydrate} from 'redux-persist' | ||
import {AsyncStorage} from 'react-native' | ||
|
||
import Firestack from 'react-native-firestack' | ||
import env from '../../config/environment' | ||
|
||
import * as currentUser from './modules/currentUser' | ||
import * as navigation from './modules/navigation' | ||
import { rootReducer, actions, initialState } from './rootReducer'; | ||
|
||
export const configureStore = (userInitialState = {}) => { | ||
const middleware = applyMiddleware(thunk); | ||
let middleware = [ | ||
thunkMiddleware, | ||
] | ||
|
||
let tools = []; | ||
if (process.env.NODE_ENV === 'development') { | ||
// const devTools = require('remote-redux-devtools'); | ||
// tools.push(devTools()); | ||
} | ||
|
||
tools.push(autoRehydrate()) | ||
|
||
const firestack = new Firestack(env.firestack) | ||
|
||
const rootReducer = combineReducers({ | ||
user: currentUser.reducer, | ||
navigation: navigation.reducer, | ||
firestack: (state) => firestack | ||
}); | ||
let finalCreateStore; | ||
finalCreateStore = compose( | ||
applyMiddleware(...middleware), | ||
...tools | ||
)(createStore); | ||
|
||
let initialState = | ||
Object.assign({}, { | ||
navigation: navigation.initialState | ||
}) | ||
const finalInitialState = Object.assign({}, | ||
initialState, | ||
userInitialState, | ||
{firestack} | ||
); | ||
|
||
const store = createStore( | ||
const store = finalCreateStore( | ||
rootReducer, | ||
initialState, | ||
middleware); | ||
finalInitialState | ||
); | ||
|
||
const persistor = persistStore(store, { | ||
storage: AsyncStorage, | ||
blacklist: ['firestack'] | ||
}); | ||
|
||
firestack.setStore(store); | ||
|
||
const dispatch = store.dispatch; | ||
const actions = { | ||
currentUser: bindActionCreators(currentUser.actions, dispatch), | ||
navigation: bindActionCreators(navigation.actions, dispatch), | ||
if (module.hot) { | ||
module.hot.accept('./rootReducer', () => { | ||
const {rootReducer} = require('./rootReducer').default; | ||
store.replaceReducer(rootReducer); | ||
}); | ||
} | ||
|
||
return {store,actions} | ||
const boundActions = bindActionCreatorsToStore(actions, store); | ||
return { | ||
store, | ||
actions: boundActions | ||
} | ||
} | ||
|
||
export default configureStore |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { combineReducers } from 'redux'; | ||
|
||
const modules = { | ||
currentUser: require('./modules/currentUser'), | ||
navigation: require('./modules/navigation'), | ||
} | ||
|
||
// const currentUser = require('./reducers/currentUser') | ||
// const navigation = require('./reducers/navigation') | ||
// const feed = require('./reducers/feed') | ||
|
||
export let actions = {} | ||
|
||
export let reducers = { | ||
'firestack': state => state || null // filled in later | ||
} | ||
export let initialState = {}; | ||
|
||
Object.keys(modules).forEach(key => { | ||
const container = modules[key]; | ||
initialState[key] = container.initialState || {}; | ||
actions[key] = container.actions; | ||
reducers[key] = container.reducer; | ||
}); | ||
|
||
export const rootReducer = combineReducers(reducers); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
|
||
import { | ||
View, | ||
Text, | ||
} from 'react-native' | ||
|
||
import appStyles from '../../../styles/app'; | ||
|
||
export class Online extends React.Component { | ||
|
||
componentWillMount() { | ||
const {firestack} = this.props; | ||
} | ||
|
||
_sendHi() { | ||
const {firestack} = this.props; | ||
} | ||
|
||
render() { | ||
return ( | ||
<View> | ||
<View style={appStyles.row}> | ||
<Text> | ||
This is a test for dealing with Presence. | ||
</Text> | ||
</View> | ||
</View> | ||
) | ||
} | ||
|
||
} | ||
|
||
export default Online |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux' | ||
import { | ||
View, | ||
Text | ||
} from 'react-native' | ||
|
||
import appStyles from '../../styles/app'; | ||
|
||
import List from '../../components/List/List' | ||
|
||
// Demos | ||
import Online from './Demos/Online'; | ||
|
||
export const Routes = { | ||
'online': { | ||
route: { | ||
title: 'Online', | ||
Component: Online | ||
} | ||
} | ||
} | ||
|
||
export class Presence extends React.Component { | ||
render() { | ||
const initialRows = [ | ||
{ title: 'Online', key: 'presence.online' } | ||
]; | ||
return ( | ||
<View style={appStyles.container}> | ||
<List | ||
initialRows={initialRows} | ||
renderRow={this._renderRow.bind(this)} | ||
onRowPress={this._onRowPress.bind(this)} | ||
/> | ||
</View> | ||
) | ||
} | ||
|
||
_renderRow(rowData, sectionID, rowID, highlightRow) { | ||
console.log(rowData) | ||
return ( | ||
<View style={[appStyles.row]}> | ||
<Text>{rowData.title}</Text> | ||
</View> | ||
) | ||
} | ||
|
||
_onRowPress(rowData) { | ||
const rowKey = rowData.key; | ||
const {actions} = this.props; | ||
const {navigation} = actions; | ||
navigation.push(rowKey, this.props); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
firestack: state.firestack | ||
}) | ||
export default connect(mapStateToProps)(Presence) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/local/env bash | ||
#!/usr/bin/env bash | ||
|
||
adb logcat | grep $(adb shell ps | grep -i com.firestackapp | cut -c10-15) | ||
adb logcat | grep $(adb shell ps | grep -i com.firestackapp | cut -c10-15) |