| 
									
										
										
										
											2015-09-08 19:32:45 -07:00
										 |  |  | import unused from './es6-shims'; // eslint-disable-line
 | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  | import Rx from 'rx'; | 
					
						
							|  |  |  | import React from 'react'; | 
					
						
							| 
									
										
										
										
											2015-07-24 17:52:07 -07:00
										 |  |  | import Fetchr from 'fetchr'; | 
					
						
							|  |  |  | import debugFactory from 'debug'; | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  | import { Router } from 'react-router'; | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  | import { createLocation, createHistory } from 'history'; | 
					
						
							| 
									
										
										
										
											2015-07-21 14:06:21 -07:00
										 |  |  | import { hydrate } from 'thundercats'; | 
					
						
							| 
									
										
										
										
											2015-07-13 00:25:01 -07:00
										 |  |  | import { Render } from 'thundercats-react'; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-01 15:14:10 -07:00
										 |  |  | import { app$ } from '../common/app'; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const debug = debugFactory('fcc:client'); | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  | const DOMContianer = document.getElementById('fcc'); | 
					
						
							| 
									
										
										
										
											2015-07-14 19:33:51 -07:00
										 |  |  | const catState = window.__fcc__.data || {}; | 
					
						
							| 
									
										
										
										
											2015-07-24 17:52:07 -07:00
										 |  |  | const services = new Fetchr({ | 
					
						
							|  |  |  |   xhrPath: '/services' | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 11:46:34 -07:00
										 |  |  | Rx.config.longStackSupport = !!debug.enabled; | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  | const history = createHistory(); | 
					
						
							|  |  |  | const appLocation = createLocation( | 
					
						
							|  |  |  |   location.pathname + location.search | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | // returns an observable
 | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  | app$({ history, location: appLocation }) | 
					
						
							| 
									
										
										
										
											2015-07-14 19:33:51 -07:00
										 |  |  |   .flatMap( | 
					
						
							|  |  |  |     ({ AppCat }) => { | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  |       // instantiate the cat with service
 | 
					
						
							| 
									
										
										
										
											2015-07-24 17:52:07 -07:00
										 |  |  |       const appCat = AppCat(null, services); | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  |       // hydrate the stores
 | 
					
						
							| 
									
										
										
										
											2015-07-21 14:06:21 -07:00
										 |  |  |       return hydrate(appCat, catState) | 
					
						
							| 
									
										
										
										
											2015-07-14 19:33:51 -07:00
										 |  |  |         .map(() => appCat); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  |     // not using nextLocation at the moment but will be used for
 | 
					
						
							|  |  |  |     // redirects in the future
 | 
					
						
							|  |  |  |     ({ nextLocation, props }, appCat) => ({ nextLocation, props, appCat }) | 
					
						
							| 
									
										
										
										
											2015-07-14 19:33:51 -07:00
										 |  |  |   ) | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  |   .flatMap(({ props, appCat }) => { | 
					
						
							| 
									
										
										
										
											2015-09-13 22:14:49 -07:00
										 |  |  |     props.history = history; | 
					
						
							| 
									
										
										
										
											2015-07-13 00:25:01 -07:00
										 |  |  |     return Render( | 
					
						
							| 
									
										
										
										
											2015-07-14 19:33:51 -07:00
										 |  |  |       appCat, | 
					
						
							| 
									
										
										
										
											2015-09-13 18:12:22 -07:00
										 |  |  |       React.createElement(Router, props), | 
					
						
							| 
									
										
										
										
											2015-07-13 00:25:01 -07:00
										 |  |  |       DOMContianer | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2015-06-29 09:50:25 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  |   .subscribe( | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  |     () => { | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  |       debug('react rendered'); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  |     err => { | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  |       debug('an error has occured', err.stack); | 
					
						
							| 
									
										
										
										
											2015-07-04 11:59:22 -07:00
										 |  |  |     }, | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       debug('react closed subscription'); | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   ); |