2015-07-04 18:59:22 +00:00
|
|
|
import Rx from 'rx';
|
2016-01-27 19:34:44 +00:00
|
|
|
import debug from 'debug';
|
2016-05-04 23:46:19 +00:00
|
|
|
import { render } from 'redux-epic';
|
2017-11-10 01:10:30 +00:00
|
|
|
import createHistory from 'history/createBrowserHistory';
|
2016-09-02 01:46:09 +00:00
|
|
|
import sendPageAnalytics from './utils/send-page-analytics';
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2017-11-10 01:10:30 +00:00
|
|
|
import { App, createApp, provideStore } from '../common/app';
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2017-08-01 03:04:01 +00:00
|
|
|
// client specific epics
|
|
|
|
import epics from './epics';
|
2016-01-27 19:34:44 +00:00
|
|
|
|
2016-06-29 20:00:22 +00:00
|
|
|
const isDev = Rx.config.longStackSupport = debug.enabled('fcc:*');
|
2016-01-27 19:34:44 +00:00
|
|
|
const log = debug('fcc:client');
|
2016-09-27 17:57:56 +00:00
|
|
|
const hotReloadTimeout = 2000;
|
2018-01-05 21:47:53 +00:00
|
|
|
const {
|
2018-01-17 18:43:41 +00:00
|
|
|
devToolsExtension,
|
2018-01-05 21:47:53 +00:00
|
|
|
location,
|
|
|
|
history: _history,
|
|
|
|
document,
|
|
|
|
ga,
|
|
|
|
__fcc__: {
|
2018-05-15 05:12:05 +00:00
|
|
|
data: defaultState = {},
|
2018-01-05 21:47:53 +00:00
|
|
|
csrf: {
|
|
|
|
token: csrfToken
|
|
|
|
} = {}
|
|
|
|
}
|
|
|
|
} = window;
|
|
|
|
const epicOptions = {
|
|
|
|
isDev,
|
|
|
|
window,
|
|
|
|
document,
|
|
|
|
location,
|
|
|
|
history: _history
|
|
|
|
};
|
|
|
|
|
2016-03-21 04:43:36 +00:00
|
|
|
const DOMContainer = document.getElementById('fcc');
|
2016-11-25 00:59:51 +00:00
|
|
|
|
2017-11-10 01:10:30 +00:00
|
|
|
defaultState.app.csrfToken = csrfToken;
|
2016-09-02 00:37:30 +00:00
|
|
|
|
2018-03-06 10:25:33 +00:00
|
|
|
const serviceOptions = {
|
|
|
|
context: { _csrf: csrfToken },
|
|
|
|
xhrPath: '/services',
|
|
|
|
xhrTimeout: 15000
|
|
|
|
};
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2018-05-15 05:12:05 +00:00
|
|
|
const history = createHistory();
|
2018-01-05 21:47:53 +00:00
|
|
|
sendPageAnalytics(history, ga);
|
2016-01-04 03:40:49 +00:00
|
|
|
|
2016-03-15 00:22:56 +00:00
|
|
|
createApp({
|
|
|
|
history,
|
|
|
|
serviceOptions,
|
2017-11-10 01:10:30 +00:00
|
|
|
defaultState,
|
2017-08-01 03:04:01 +00:00
|
|
|
epics,
|
|
|
|
epicOptions,
|
2018-05-16 14:22:43 +00:00
|
|
|
enhancers: isDev && devToolsExtension && [ devToolsExtension() ]
|
2016-03-15 00:22:56 +00:00
|
|
|
})
|
2018-05-15 05:12:05 +00:00
|
|
|
.doOnNext(() => {
|
2016-03-15 00:22:56 +00:00
|
|
|
if (module.hot && typeof module.hot.accept === 'function') {
|
2018-01-05 23:09:50 +00:00
|
|
|
module.hot.accept(() => {
|
|
|
|
// note(berks): not sure this ever runs anymore after adding
|
|
|
|
// RHR?
|
2016-09-27 17:57:56 +00:00
|
|
|
log('saving state and refreshing.');
|
|
|
|
log('ignore react ssr warning.');
|
2018-01-05 21:47:53 +00:00
|
|
|
setTimeout(() => location.reload(), hotReloadTimeout);
|
2016-03-15 00:22:56 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-29 16:50:25 +00:00
|
|
|
})
|
2018-01-08 19:12:00 +00:00
|
|
|
.do(() => log('rendering'))
|
2017-11-10 01:10:30 +00:00
|
|
|
.flatMap(({ store }) => render(provideStore(App, store), DOMContainer))
|
2015-06-18 04:04:28 +00:00
|
|
|
.subscribe(
|
2016-01-27 19:34:44 +00:00
|
|
|
() => debug('react rendered'),
|
|
|
|
err => { throw err; },
|
|
|
|
() => debug('react closed subscription')
|
2015-06-18 04:04:28 +00:00
|
|
|
);
|