Created
June 14, 2018 12:20
-
-
Save macrozone/fb9eb12ffa117b76b07896fbae2f7a3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { compose } from 'recompose' | |
import { connect } from 'react-redux' | |
import { withNavigationFocus } from 'react-navigation' | |
import { graphql } from 'react-apollo' | |
import { isFunction } from 'lodash' | |
import type { State } from '../../../redux/rootReducer' | |
export const defaultOptions = polling => ({ | |
pollInterval: polling ? DEFAULT_POLL_INTERVAL : 0, | |
errorPolicy: 'ignore', | |
}) | |
export default (query, { options = {}, ...otherConfig } = {}) => | |
compose( | |
withNavigationFocus, | |
connect((state: State) => ({ | |
inForeground: state.core.device.inForeground, | |
})), | |
graphql(query, { | |
...otherConfig, | |
options: props => { | |
const result = { | |
...defaultOptions(shouldPoll(props)), | |
...(isFunction(options) ? options(props) : options), | |
} | |
// console.log(result) | |
return result | |
}, | |
}), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment