forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminPendingTime.js
More file actions
42 lines (36 loc) · 1.04 KB
/
minPendingTime.js
File metadata and controls
42 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as types from '../constants/ActionTypes';
let sequenceList = {};
const minPendingTime = 500;
/*
* I just use this to fix a bugs about when the request is too quickly, the RefreshControl can't update the refreshing.
* It's a bug, but I don't know how to fix it, so use this hack way to do it.
* */
export default function ({dispatch}) {
return next => action => {
const {meta={}, payload} = action;
const {sequence={}, tab} = meta;
if (action.type === types.UPDATE_TOPICS_BY_TAB) {
if (sequence.type == 'start') {
sequenceList[sequence.id] = {
start: new Date().getTime()
};
return next(action);
}
if (sequence.type == 'next' && sequenceList[sequence.id]) {
let start = sequenceList[sequence.id].start;
let end = new Date().getTime();
let leftTime = minPendingTime - (end - start);
delete sequenceList[sequence.id];
if (leftTime < 0) {
return next(action);
}
else {
return setTimeout(()=> {
next(action);
}, leftTime);
}
}
}
return next(action);
};
}