Skip to content

Instantly share code, notes, and snippets.

@suhanlee
Last active May 18, 2018 08:06
Show Gist options
  • Save suhanlee/c1e13d38a4d39cf2697f0cb28b908186 to your computer and use it in GitHub Desktop.
Save suhanlee/c1e13d38a4d39cf2697f0cb28b908186 to your computer and use it in GitHub Desktop.
redux-segement-react-native
import { createStore, applyMiddleware } from ‘redux’;
import { takeEvery, call } from ‘redux-saga/effects’;
import createSegmentTracker from ‘redux-segment-node’;
import { navigateTo } from ‘gatsby-link’;
import { flow } from ‘lodash/fp’;
import { NAVIGATE_TO, GET_CLIENT_INFORMATION } from ‘~/shared/store/app/actionTypes’;
import { SEGMENT_KEY as key } from ‘~/shared/constants’;
import {
middlewares,
sagaMiddleware,
sagas,
reducers,
initialState,
initializeStore,
composeEnhancers,
} from ‘~/shared/store’;
const segmentMiddleware = createSegmentTracker({
key,
flushAfter: 1000,
});
const middleware = applyMiddleware.apply(null, [...middlewares, segmentMiddleware]);
const store = createStore(reducers, initialState, composeEnhancers(middleware));
const webInitializer = (webStore) => {
webStore.dispatch({
type: GET_CLIENT_INFORMATION,
clientInformation: {
userAgent: navigator.userAgent,
locale: navigator.language,
},
});
return webStore;
};
export default flow(webInitializer, initializeStore)(store);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment