Last active
September 22, 2016 21:59
-
-
Save auser/85068c99c9d80933e989ed6b58439172 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 React from 'react' | |
import { Provider } from 'react-redux' | |
import { AppRegistry } from 'react-native'; | |
import App from './containers/App' | |
import { | |
configureStore | |
} from './redux/configureStore' | |
const {store, actions} = configureStore(); | |
class Container extends React.Component { | |
render() { | |
return ( | |
<Provider store={store}> | |
<App actions={actions} /> | |
</Provider> | |
) | |
} | |
} | |
AppRegistry.registerComponent('MyApp', () => Container) |
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
// all the normal configureStore stuff (in this case, as a function) | |
import { applyMiddleware, combineReducers, createStore } from 'redux' | |
import { bindActionCreators } from 'redux' | |
import thunk from 'redux-thunk' | |
import Firestack from 'react-native-firestack' | |
import env from '../../config/environment' | |
import createEventsModule from './modules/events' | |
export const configureStore = (initialState = {}) => { | |
const middleware = applyMiddleware(thunk); | |
const firestack = new Firestack(env.firestack) | |
const events = createEventsModule(firestack); | |
const rootReducer = combineReducers({ | |
events: events.reducer, | |
firestack: (state) => firestack | |
}); | |
const store = createStore( | |
rootReducer, | |
initialState, | |
middleware); | |
firestack.setStore(store); | |
const dispatch = store.dispatch; | |
const actions = { | |
events: bindActionCreators(events.actions, dispatch) | |
} | |
return {store,actions} | |
} | |
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 is an example firestack redux module | |
import {createConstants, createReducer} from 'redux-module-builder' | |
import {FirestackModule} from 'react-native-firestack' | |
export const createModule = (firestack, options={}) => { | |
const inst = new FirestackModule('events', {firestack}); | |
export const types = createConstants({ | |
prefix: 'events' | |
})( | |
inst.types, | |
'LIST', | |
'RECEIVED' | |
); | |
const initialState = inst.initialState; | |
export const reducer = createReducer({ | |
[types.RECEIVED]: (state, {payload}) => { | |
return { | |
...state, | |
eventListing: payload | |
} | |
}, | |
...inst.reducer | |
}); | |
const actions = { | |
export const actions = { | |
...inst.actions, | |
init: () => (dispatch, getState) => { | |
// init goes here | |
} | |
} | |
} | |
return {initialState, actions, reducer, CONSTANTS} | |
} | |
export default createModule; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@auser
IMHO events.js without redux-module-builder could be more beginner friendly
Also I get this eslint error in events.js