Skip to content

Commit def4c99

Browse files
committed
Fix for the issue #20
1 parent 414a08c commit def4c99

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import ResizeObserverPolyfill from './ResizeObserver.js';
2+
import global from './shims/global.js';
23

34
export default (() => {
45
// Export existing implementation if available.
5-
if (typeof ResizeObserver != 'undefined') {
6-
// eslint-disable-next-line no-undef
7-
return ResizeObserver;
6+
if (typeof global.ResizeObserver != 'undefined') {
7+
return global.ResizeObserver;
88
}
99

1010
return ResizeObserverPolyfill;

src/shims/global.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default (() => {
2+
if (typeof global != 'undefined' && global.Math === Math) {
3+
return global;
4+
}
5+
6+
if (typeof self != 'undefined' && self.Math === Math) {
7+
return self;
8+
}
9+
10+
if (typeof window != 'undefined' && window.Math === Math) {
11+
return window;
12+
}
13+
14+
// eslint-disable-next-line no-new-func
15+
return Function('return this')();
16+
})();

src/shims/requestAnimationFrame.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import global from './global.js';
2+
13
/**
24
* A shim for the requestAnimationFrame which falls back to the setTimeout if
35
* first one is not supported.
@@ -6,7 +8,10 @@
68
*/
79
export default (() => {
810
if (typeof requestAnimationFrame === 'function') {
9-
return requestAnimationFrame;
11+
// It's required to use a bounded function because IE sometimes throws
12+
// an "Invalid calling object" error if rAF is invoked without the global
13+
// object on the left hand side.
14+
return requestAnimationFrame.bind(global);
1015
}
1116

1217
return callback => setTimeout(() => callback(Date.now()), 1000 / 60);

0 commit comments

Comments
 (0)