import { pick , pickBy , contains } from 'ramda' ; import { Action , AnyAction } from 'typescript-fsa' ; import { NavigationAction } from 'react-navigation' ; import { create } from 'apisauce' ; import { HOST } from 'config' ; interface IWaitForRoute { routeName : string ; actions : [ { routeName : string ; } ] ; } ; export function waitForRoute ( route ) { return ( action ) => { return ( action . type . indexOf ( 'Navigation' ) !== - 1 && ( ( action . routeName && action . routeName === route ) || ( action . actions && action . actions . find ( ( { routeName } ) => route === routeName ) ) ) ) ; } ; } export function waitForError ( ) { return ( action ) => { return action . type && action . type . indexOf ( '_FAILED' ) !== - 1 ; } ; } export const resolveParams = ( values = { } , formValues ? ) => { const result = { } ; const keys = Object . keys ( values ) ; keys . forEach ( key => { const param = values [ key ] ; switch ( param . type ) { case 'text' : result [ key ] = param . text ; break ; case 'Val' : const inputName = param . params [ 0 ] ; const inputValue = formValues && formValues [ inputName ] ; result [ key ] = inputValue ; break ; default : break ; } } ) ; return result ; } ; export const waitForActionWithParams = ( actionType , params = [ ] ) => ( action ) : boolean => { return ( action && action . type === actionType && Object . keys ( pickBy ( ( value , key ) => contains ( key , params ) && ! ! value ) ( action . payload ) ) . length === params . length ) ; } ; const HISTORY_SAGA = Symbol ( '@@redux-saga/HISTORY' ) ; export const hasHistoryMarker = ( action ) => action [ HISTORY_SAGA ] ; export const addHistoryMarker = ( action ) => ( { [ HISTORY_SAGA ] : true , ... action } ) ; export const filterDuplicateNodes = ( nodes ) : INode [ ] => { return nodes . reduce ( ( acc , el ) => { acc = acc || [ ] ; let duplicate = acc . find ( ( item ) => item . apiUrl === el . apiUrl ) ; if ( ! duplicate || duplicate . length <= 1 ) { acc . push ( el ) ; } return acc ; } , 0 ) ; } ;