raf.js
979 Bytes
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
43
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = wrapperRaf;
var _raf = _interopRequireDefault(require("rc-util/lib/raf"));
var id = 0;
var ids = {}; // Support call raf with delay specified frame
function wrapperRaf(callback) {
var delayFrames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var myId = id++;
var restFrames = delayFrames;
function internalCallback() {
restFrames -= 1;
if (restFrames <= 0) {
callback();
delete ids[myId];
} else {
ids[myId] = (0, _raf["default"])(internalCallback);
}
}
ids[myId] = (0, _raf["default"])(internalCallback);
return myId;
}
wrapperRaf.cancel = function cancel(pid) {
if (pid === undefined) return;
_raf["default"].cancel(ids[pid]);
delete ids[pid];
};
wrapperRaf.ids = ids; // export this for test usage