| 
									
										
										
										
											2018-02-20 13:07:32 +00:00
										 |  |  | import { ofType } from 'redux-epic'; | 
					
						
							|  |  |  | import debug from 'debug'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   types as appTypes, | 
					
						
							| 
									
										
										
										
											2018-05-15 06:12:05 +01:00
										 |  |  |   createErrorObservable | 
					
						
							| 
									
										
										
										
											2018-02-20 13:07:32 +00:00
										 |  |  | } from '../../redux'; | 
					
						
							|  |  |  | import { types, fetchMapUiComplete } from './'; | 
					
						
							|  |  |  | import { shapeChallenges } from '../../redux/utils'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const isDev = debug.enabled('fcc:*'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default function fetchMapUiEpic( | 
					
						
							|  |  |  |   actions, | 
					
						
							| 
									
										
										
										
											2018-05-15 06:12:05 +01:00
										 |  |  |   _, | 
					
						
							| 
									
										
										
										
											2018-02-20 13:07:32 +00:00
										 |  |  |   { services } | 
					
						
							|  |  |  | ) { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:56:26 +01:00
										 |  |  |   return actions::ofType( | 
					
						
							| 
									
										
										
										
											2018-02-23 12:20:13 +00:00
										 |  |  |     appTypes.appMounted, | 
					
						
							|  |  |  |     types.fetchMapUi.start | 
					
						
							| 
									
										
										
										
											2018-02-20 13:07:32 +00:00
										 |  |  |   ) | 
					
						
							|  |  |  |     .flatMapLatest(() => { | 
					
						
							|  |  |  |       const options = { | 
					
						
							|  |  |  |         service: 'map-ui' | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       return services.readService$(options) | 
					
						
							|  |  |  |         .retry(3) | 
					
						
							|  |  |  |         .map(({ entities, ...res }) => ({ | 
					
						
							|  |  |  |           entities: shapeChallenges( | 
					
						
							|  |  |  |             entities, | 
					
						
							|  |  |  |             isDev | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           ...res | 
					
						
							|  |  |  |         })) | 
					
						
							| 
									
										
										
										
											2018-02-23 12:20:13 +00:00
										 |  |  |         .map(fetchMapUiComplete) | 
					
						
							| 
									
										
										
										
											2018-02-20 13:07:32 +00:00
										 |  |  |         .catch(createErrorObservable); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } |