| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | import './es6-shims'; | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  | import Rx from 'rx'; | 
					
						
							|  |  |  | import React from 'react'; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | import debug from 'debug'; | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  | import { Router } from 'react-router'; | 
					
						
							| 
									
										
										
										
											2016-06-14 09:31:41 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   routerMiddleware, | 
					
						
							|  |  |  |   routerReducer as routing, | 
					
						
							|  |  |  |   syncHistoryWithStore | 
					
						
							|  |  |  | } from 'react-router-redux'; | 
					
						
							| 
									
										
										
										
											2016-05-04 16:46:19 -07:00
										 |  |  | import { render } from 'redux-epic'; | 
					
						
							| 
									
										
										
										
											2016-03-02 19:45:54 -08:00
										 |  |  | import { createHistory } from 'history'; | 
					
						
							| 
									
										
										
										
											2016-07-21 16:35:37 -07:00
										 |  |  | import useLangRoutes from './utils/use-lang-routes'; | 
					
						
							| 
									
										
										
										
											2016-09-01 18:46:09 -07:00
										 |  |  | import sendPageAnalytics from './utils/send-page-analytics'; | 
					
						
							|  |  |  | import flashToToast from './utils/flash-to-toast'; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  | import createApp from '../common/app'; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | import provideStore from '../common/app/provide-store'; | 
					
						
							| 
									
										
										
										
											2016-11-25 00:59:51 +00:00
										 |  |  | import { getLangFromPath } from '../common/app/utils/lang'; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | // client specific sagas
 | 
					
						
							|  |  |  | import sagas from './sagas'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   isColdStored, | 
					
						
							|  |  |  |   getColdStorage, | 
					
						
							|  |  |  |   saveToColdStorage | 
					
						
							|  |  |  | } from './cold-reload'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 13:00:22 -07:00
										 |  |  | const isDev = Rx.config.longStackSupport = debug.enabled('fcc:*'); | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | const log = debug('fcc:client'); | 
					
						
							| 
									
										
										
										
											2016-09-27 10:57:56 -07:00
										 |  |  | const hotReloadTimeout = 2000; | 
					
						
							| 
									
										
										
										
											2016-10-27 23:10:24 +01:00
										 |  |  | const { csrf: { token: csrfToken } = {} } = window.__fcc__; | 
					
						
							| 
									
										
										
										
											2016-03-20 21:43:36 -07:00
										 |  |  | const DOMContainer = document.getElementById('fcc'); | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  | const initialState = isColdStored() ? | 
					
						
							|  |  |  |   getColdStorage() : | 
					
						
							|  |  |  |   window.__fcc__.data; | 
					
						
							| 
									
										
										
										
											2016-11-25 00:59:51 +00:00
										 |  |  | const primaryLang = getLangFromPath(window.location.pathname); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 10:13:02 -07:00
										 |  |  | initialState.app.csrfToken = csrfToken; | 
					
						
							| 
									
										
										
										
											2016-09-01 18:46:09 -07:00
										 |  |  | initialState.toasts = flashToToast(window.__fcc__.flash); | 
					
						
							| 
									
										
										
										
											2016-09-01 17:37:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-27 10:57:56 -07:00
										 |  |  | // make empty object so hot reload works
 | 
					
						
							|  |  |  | window.__fcc__ = {}; | 
					
						
							| 
									
										
										
										
											2016-09-01 17:37:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 10:13:02 -07:00
										 |  |  | const serviceOptions = { xhrPath: '/services', context: { _csrf: csrfToken } }; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-25 00:59:51 +00:00
										 |  |  | const history = useLangRoutes(createHistory, primaryLang)(); | 
					
						
							| 
									
										
										
										
											2016-07-21 16:35:37 -07:00
										 |  |  | sendPageAnalytics(history, window.ga); | 
					
						
							| 
									
										
										
										
											2015-10-27 23:46:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | const devTools = window.devToolsExtension ? window.devToolsExtension() : f => f; | 
					
						
							| 
									
										
										
										
											2016-06-14 09:31:41 -07:00
										 |  |  | const adjustUrlOnReplay = !!window.devToolsExtension; | 
					
						
							| 
									
										
										
										
											2015-10-27 20:07:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-24 21:54:48 -07:00
										 |  |  | const sagaOptions = { | 
					
						
							| 
									
										
										
										
											2016-05-11 21:14:08 -07:00
										 |  |  |   isDev, | 
					
						
							| 
									
										
										
										
											2016-04-24 21:54:48 -07:00
										 |  |  |   window, | 
					
						
							|  |  |  |   document: window.document, | 
					
						
							| 
									
										
										
										
											2016-06-17 22:20:20 -07:00
										 |  |  |   location: window.location, | 
					
						
							|  |  |  |   history: window.history | 
					
						
							| 
									
										
										
										
											2016-04-24 21:54:48 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-01-03 19:40:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  | createApp({ | 
					
						
							|  |  |  |     history, | 
					
						
							| 
									
										
										
										
											2016-06-14 09:31:41 -07:00
										 |  |  |     syncHistoryWithStore, | 
					
						
							|  |  |  |     syncOptions: { adjustUrlOnReplay }, | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  |     serviceOptions, | 
					
						
							| 
									
										
										
										
											2016-09-01 18:46:09 -07:00
										 |  |  |     initialState, | 
					
						
							| 
									
										
										
										
											2016-06-14 09:31:41 -07:00
										 |  |  |     middlewares: [ routerMiddleware(history) ], | 
					
						
							| 
									
										
										
										
											2016-05-20 12:42:26 -07:00
										 |  |  |     sagas: [...sagas ], | 
					
						
							| 
									
										
										
										
											2016-04-24 21:54:48 -07:00
										 |  |  |     sagaOptions, | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  |     reducers: { routing }, | 
					
						
							|  |  |  |     enhancers: [ devTools ] | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   .doOnNext(({ store }) => { | 
					
						
							|  |  |  |     if (module.hot && typeof module.hot.accept === 'function') { | 
					
						
							| 
									
										
										
										
											2016-09-27 10:57:56 -07:00
										 |  |  |       module.hot.accept(err => { | 
					
						
							|  |  |  |         if (err) { console.error(err); } | 
					
						
							|  |  |  |         log('saving state and refreshing.'); | 
					
						
							|  |  |  |         log('ignore react ssr warning.'); | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  |         saveToColdStorage(store.getState()); | 
					
						
							|  |  |  |         setTimeout(() => window.location.reload(), hotReloadTimeout); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-29 09:50:25 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-03-14 17:22:56 -07:00
										 |  |  |   .doOnNext(() => log('rendering')) | 
					
						
							| 
									
										
										
										
											2016-09-01 17:37:30 -07:00
										 |  |  |   .flatMap( | 
					
						
							|  |  |  |     ({ props, store }) => render( | 
					
						
							|  |  |  |       provideStore(React.createElement(Router, props), store), | 
					
						
							|  |  |  |       DOMContainer | 
					
						
							|  |  |  |     ), | 
					
						
							|  |  |  |     ({ store }) => store | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  |   .subscribe( | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |     () => debug('react rendered'), | 
					
						
							|  |  |  |     err => { throw err; }, | 
					
						
							|  |  |  |     () => debug('react closed subscription') | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  |   ); |