-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
60 lines (51 loc) · 1.33 KB
/
Copy pathexample.js
File metadata and controls
60 lines (51 loc) · 1.33 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const {
nextFrame, loop, sequence, delay, throttleFrames, waitFrames,
} = require('./lib');
const now = require('performance-now');
const increment = val => val + 1;
const sequenceValues = [1, 2, 3, 4];
let frameCount = 0;
let throttleCount = 0;
const start = now();
/** **************************
nextFrame / frame
*************************** */
nextFrame()
.then(() => {
console.log('next frame');
});
/** **************************
delay
*************************** */
delay(1000).then(() => {
console.log(`delayed ${now() - start}ms`);
});
/** **************************
sequence / frameSequence
*************************** */
sequence(sequenceValues, increment)
.then(result => console.log(result));
/** **************************
loop / nextFrames / onEnterFrame
*************************** */
const cancelLoop = loop(() => {
console.log('frame', frameCount += 1);
if (frameCount >= 100) {
cancelLoop();
}
});
/** **************************
throttleFrames / throttle
*************************** */
const cancelThrottle = throttleFrames(() => {
console.log('throttle', throttleCount += 1);
if (throttleCount >= 10) {
cancelThrottle();
}
}, 10);
/** **************************
waitFrames / wait
*************************** */
waitFrames(50).then((count) => {
console.log(`${count} frames waited`);
});