Throttle instead of debounce

This commit is contained in:
Chi Vinh Le
2017-11-30 21:44:32 +01:00
parent 06ddb30d77
commit 65be2b89a4
2 changed files with 7 additions and 7 deletions
@@ -138,7 +138,7 @@ class ModerationContainer extends Component {
},
];
this.subscriptions = parameters.map((param) => this.props.data.subscribeToMoreDebounced(param));
this.subscriptions = parameters.map((param) => this.props.data.subscribeToMoreThrottled(param));
}
unsubscribe() {
+6 -6
View File
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import hoistStatics from 'recompose/hoistStatics';
import {getOperationName} from 'apollo-client/queries/getFromAST';
import {addTypenameToDocument} from 'apollo-client/queries/queryTransform';
import debounce from 'lodash/debounce';
import throttle from 'lodash/throttle';
const withSkipOnErrors = (reducer) => (prev, action, ...rest) => {
if (action.type === 'APOLLO_MUTATION_RESULT' && getResponseErrors(action.result)) {
@@ -81,7 +81,7 @@ export default (document, config = {}) => hoistStatics((WrappedComponent) => {
this.context.eventEmitter.emit(`query.${this.name}.${status}`, {variables, data: root});
}
subscribeToMoreDebounced = ({document, variables, updateQuery}) => {
subscribeToMoreThrottled = ({document, variables, updateQuery}, wait = 1000) => {
// We need to add the typenames and resolve fragments.
const rootQuery = addTypenameToDocument(this.resolvedDocument);
@@ -114,8 +114,8 @@ export default (document, config = {}) => hoistStatics((WrappedComponent) => {
batched = [];
};
// Debounce to handle high loads of traffic.
const processDataDebounced = debounce(processData, 250, {'maxWait': 2000});
// throttle to handle high loads of traffic.
const processDataThrottled = throttle(processData, wait);
const handler = (error, data) => {
if (error) {
@@ -126,7 +126,7 @@ export default (document, config = {}) => hoistStatics((WrappedComponent) => {
}
if (data) {
batched.push(data);
processDataDebounced();
processDataThrottled();
}
};
@@ -173,7 +173,7 @@ export default (document, config = {}) => hoistStatics((WrappedComponent) => {
stopPolling: data.stopPolling,
refetch: data.refetch,
updateQuery: data.updateQuery,
subscribeToMoreDebounced: this.subscribeToMoreDebounced,
subscribeToMoreThrottled: this.subscribeToMoreThrottled,
subscribeToMore: (stmArgs) => {
const resolvedDocument = this.resolveDocument(stmArgs.document);