diff --git a/client/index.js b/client/index.js index d67cd8f7b9..60d2dc64f2 100644 --- a/client/index.js +++ b/client/index.js @@ -1,4 +1,5 @@ import './es6-shims'; +import _ from 'lodash'; import Rx from 'rx'; import debug from 'debug'; import { render } from 'redux-epic'; @@ -22,33 +23,41 @@ import { const isDev = Rx.config.longStackSupport = debug.enabled('fcc:*'); const log = debug('fcc:client'); const hotReloadTimeout = 2000; -const { csrf: { token: csrfToken } = {} } = window.__fcc__; +const { + devToolsExtension = _.noop, + location, + history: _history, + document, + ga, + __fcc__: { + flash = [], + data: ssrState = {}, + csrf: { + token: csrfToken + } = {} + } +} = window; +const epicOptions = { + isDev, + window, + document, + location, + history: _history +}; + const DOMContainer = document.getElementById('fcc'); const defaultState = isColdStored() ? getColdStorage() : - window.__fcc__.data; -const primaryLang = getLangFromPath(window.location.pathname); + ssrState; +const primaryLang = getLangFromPath(location.pathname); defaultState.app.csrfToken = csrfToken; -defaultState.toasts = flashToToast(window.__fcc__.flash); - -// make empty object so hot reload works -window.__fcc__ = {}; +defaultState.toasts = flashToToast(flash); const serviceOptions = { xhrPath: '/services', context: { _csrf: csrfToken } }; const history = useLangRoutes(createHistory, primaryLang)(); -sendPageAnalytics(history, window.ga); - -const devTools = window.devToolsExtension ? window.devToolsExtension() : f => f; - -const epicOptions = { - isDev, - window, - document: window.document, - location: window.location, - history: window.history -}; +sendPageAnalytics(history, ga); createApp({ history, @@ -56,7 +65,7 @@ createApp({ defaultState, epics, epicOptions, - enhancers: [ devTools ] + enhancers: [ devToolsExtension() ] }) .doOnNext(({ store }) => { if (module.hot && typeof module.hot.accept === 'function') { @@ -65,7 +74,7 @@ createApp({ log('saving state and refreshing.'); log('ignore react ssr warning.'); saveToColdStorage(store.getState()); - setTimeout(() => window.location.reload(), hotReloadTimeout); + setTimeout(() => location.reload(), hotReloadTimeout); }); } })