Skip to content

Commit 79a740c

Browse files
authored
Rename variables to remove references to 'global' global (#12931)
**what is the change?:** In a recent PR we were referencing some global variables and storing local references to them. To make things more natural, we co-opted the original name of the global for our local reference. To make this work with Flow, we get the original reference from 'window.requestAnimationFrame' and assign it to 'const requestAnimationFrame'. Sometimes React is used in an environment where 'window' is not defined - in that case we need to use something else, or hide the 'window' reference somewhere. We opted to use 'global' thinking that Babel transforms would fill that in with the proper thing. But for some of our fixtures we are not doing that transform on the bundle. **why make this change?:** I want to unbreak this on master and then investigate more about what we should do to fix this. **test plan:** run `yarn build` and open the fixtures. **issue:** #12930
1 parent ff724d3 commit 79a740c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

packages/react-scheduler/src/ReactScheduler.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
4747
// We capture a local reference to any global, in case it gets polyfilled after
4848
// this module is initially evaluated.
4949
// We want to be using a consistent implementation.
50-
const Date = global.Date;
51-
const setTimeout = global.setTimeout;
52-
const clearTimeout = global.clearTimeout;
50+
const localDate = Date;
51+
const localSetTimeout = setTimeout;
52+
const localClearTimeout = clearTimeout;
5353

5454
const hasNativePerformanceNow =
5555
typeof performance === 'object' && typeof performance.now === 'function';
@@ -62,7 +62,7 @@ if (hasNativePerformanceNow) {
6262
};
6363
} else {
6464
now = function() {
65-
return Date.now();
65+
return localDate.now();
6666
};
6767
}
6868

@@ -86,7 +86,7 @@ if (!ExecutionEnvironment.canUseDOM) {
8686
next: null,
8787
prev: null,
8888
};
89-
const timeoutId = setTimeout(() => {
89+
const timeoutId = localSetTimeout(() => {
9090
callback({
9191
timeRemaining() {
9292
return Infinity;
@@ -101,7 +101,7 @@ if (!ExecutionEnvironment.canUseDOM) {
101101
const callback = callbackId.scheduledCallback;
102102
const timeoutId = timeoutIds.get(callback);
103103
timeoutIds.delete(callbackId);
104-
clearTimeout(timeoutId);
104+
localClearTimeout(timeoutId);
105105
};
106106
} else {
107107
let headOfPendingCallbacksLinkedList: CallbackConfigType | null = null;
@@ -232,7 +232,7 @@ if (!ExecutionEnvironment.canUseDOM) {
232232
};
233233
// Assumes that we have addEventListener in this environment. Might need
234234
// something better for old IE.
235-
global.addEventListener('message', idleTick, false);
235+
window.addEventListener('message', idleTick, false);
236236

237237
const animationTick = function(rafTime) {
238238
isAnimationFrameScheduled = false;

packages/shared/requestAnimationFrameForReact.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import warning from 'fbjs/lib/warning';
1515
// We capture a local reference to any global, in case it gets polyfilled after
1616
// this module is initially evaluated.
1717
// We want to be using a consistent implementation.
18-
const requestAnimationFrame = global.requestAnimationFrame;
18+
const localRequestAnimationFrame = requestAnimationFrame;
1919

2020
if (__DEV__) {
2121
if (
2222
ExecutionEnvironment.canUseDOM &&
23-
typeof requestAnimationFrame !== 'function'
23+
typeof localRequestAnimationFrame !== 'function'
2424
) {
2525
warning(
2626
false,
@@ -30,4 +30,4 @@ if (__DEV__) {
3030
}
3131
}
3232

33-
export default requestAnimationFrame;
33+
export default localRequestAnimationFrame;

0 commit comments

Comments
 (0)