Introduce separateDataAndRoot

This commit is contained in:
Chi Vinh Le
2017-04-26 01:10:16 +07:00
parent df2c33ac35
commit f142f3a27f
2 changed files with 26 additions and 9 deletions
@@ -6,7 +6,7 @@ import isEqual from 'lodash/isEqual';
import {Spinner} from 'coral-ui';
import {authActions, assetActions, pym} from 'coral-framework';
import {getDefinitionName} from 'coral-framework/utils';
import {getDefinitionName, separateDataAndRoot} from 'coral-framework/utils';
import Embed from '../components/Embed';
import {setCommentCountCache, viewAllComments} from '../actions/stream';
import {setActiveTab} from '../actions/embed';
@@ -84,14 +84,7 @@ export const withQuery = graphql(EMBED_QUERY, {
excludeIgnored: Boolean(auth && auth.user && auth.user.id),
},
}),
props: ({data: {
fetchMore, loading, networkStatus, refetch, startPolling,
stopPolling, subscribeToMore, updateQuery, variables,
...root}}) => ({
data: {fetchMore, loading, networkStatus, refetch, startPolling,
stopPolling, subscribeToMore, updateQuery, variables},
root,
}),
props: ({data}) => separateDataAndRoot(data),
});
const mapStateToProps = state => ({
+24
View File
@@ -37,3 +37,27 @@ export function getDefinitionName(doc, pos = 0) {
return doc.definitions[pos].name.value;
}
/**
* Separate apollo `data` props into `data` and `root`.
* `data` will contain props like `loading`, `fetchMore`...
* while `root` contains the actual query data.
*/
export function separateDataAndRoot(
{
fetchMore,
loading,
networkStatus,
refetch,
startPolling,
stopPolling,
subscribeToMore,
updateQuery,
variables,
...root,
}) {
return {
data: {fetchMore, loading, networkStatus, refetch, startPolling,
stopPolling, subscribeToMore, updateQuery, variables},
root,
};
}