File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -13,3 +13,32 @@ export function onlyChild(children) {
13
13
export function filterNullChildren ( children ) {
14
14
return children && children . filter ( i => i !== null ) ;
15
15
}
16
+
17
+ export const requestAnimationFrame = ( ( ) => {
18
+ let raf ;
19
+
20
+ if ( typeof window !== 'undefined' ) {
21
+ raf = window . requestAnimationFrame ;
22
+ const prefixes = [ 'ms' , 'moz' , 'webkit' , 'o' ] ;
23
+ for ( let i = 0 ; i < prefixes . length ; i ++ ) {
24
+ if ( raf ) break ;
25
+ raf = window [ `${ prefixes [ i ] } RequestAnimationFrame}` ] ;
26
+ }
27
+ }
28
+
29
+ if ( ! raf ) {
30
+ let timeLast = 0 ;
31
+ raf = ( callback ) => {
32
+ const timeCurrent = new Date ( ) . getTime ( ) ;
33
+
34
+ /* Dynamically set the delay on a per-tick basis to more closely match 60fps. */
35
+ /* Technique by Erik Moller. MIT license: https://gist.github.com/paulirish/1579671. */
36
+ const timeDelta = Math . max ( 0 , 16 - ( timeCurrent - timeLast ) ) ;
37
+ timeLast = timeCurrent + timeDelta ;
38
+
39
+ return setTimeout ( ( ) => { callback ( timeCurrent + timeDelta ) ; } , timeDelta ) ;
40
+ } ;
41
+ }
42
+
43
+ return raf ;
44
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments