Skip to content

Commit

Permalink
Check pending keys in a setImmediate to fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Ashcraft committed May 9, 2017
1 parent c2ade70 commit 2739712
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"lodash.values": "^4.3.0",
"prop-types": "^15.5.6",
"react-addons-shallow-compare": "^15.4.2",
"setimmediate": "^1.0.5",
"superagent": "^1.6.1"
},
"peerDependencies": {
Expand Down
13 changes: 8 additions & 5 deletions src/components/connect-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import includes from 'lodash.includes';
import intersection from 'lodash.intersection';
import React from 'react';
import shallowCompare from 'react-addons-shallow-compare';
import setImmediate from 'setimmediate';

import { requestAsync, cancelQuery } from '../actions';
import { reconcileQueryKey } from '../lib/query-key';
Expand Down Expand Up @@ -77,12 +78,14 @@ const connectRequest = (mapPropsToConfigs, options = {}) => WrappedComponent =>
}

cancelPendingRequests(cancelKeys) {
const { dispatch } = this.context.store;
const pendingKeys = Object.keys(this._pendingRequests);
setImmediate(() => {
const { dispatch } = this.context.store;
const pendingKeys = Object.keys(this._pendingRequests);

ensureArray(cancelKeys)
.filter(key => includes(pendingKeys, key))
.forEach(queryKey => dispatch(cancelQuery(queryKey)));
ensureArray(cancelKeys)
.filter(key => includes(pendingKeys, key))
.forEach(queryKey => dispatch(cancelQuery(queryKey)));
});
}

requestAsync(configs, force = false, retry = false) {
Expand Down

0 comments on commit 2739712

Please sign in to comment.