@samitouri / QOS-React / commits / 79a740c6e3

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:** https://github.com/facebook/react/issues/12930

Flarnie Marchan committed May 29, 2018 at 17:54 UTC 79a740c6e32ca300d4e7ff55ab06de172d4237fd
2 files changed +10 -10
packages/react-scheduler/src/ReactScheduler.js
+7 -7
@@ -47,9 +47,9 @@ import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
47 // We capture a local reference to any global, in case it gets polyfilled after
48 // this module is initially evaluated.
49 // 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;
53
54 const hasNativePerformanceNow =
55 typeof performance === 'object' && typeof performance.now === 'function';
@@ -62,7 +62,7 @@ if (hasNativePerformanceNow) {
62 };
63 } else {
64 now = function() {
65 - return Date.now();
65 + return localDate.now();
66 };
67 }
68
@@ -86,7 +86,7 @@ if (!ExecutionEnvironment.canUseDOM) {
86 next: null,
87 prev: null,
88 };
89 - const timeoutId = setTimeout(() => {
89 + const timeoutId = localSetTimeout(() => {
90 callback({
91 timeRemaining() {
92 return Infinity;
@@ -101,7 +101,7 @@ if (!ExecutionEnvironment.canUseDOM) {
101 const callback = callbackId.scheduledCallback;
102 const timeoutId = timeoutIds.get(callback);
103 timeoutIds.delete(callbackId);
104 - clearTimeout(timeoutId);
104 + localClearTimeout(timeoutId);
105 };
106 } else {
107 let headOfPendingCallbacksLinkedList: CallbackConfigType | null = null;
@@ -232,7 +232,7 @@ if (!ExecutionEnvironment.canUseDOM) {
232 };
233 // Assumes that we have addEventListener in this environment. Might need
234 // something better for old IE.
235 - global.addEventListener('message', idleTick, false);
235 + window.addEventListener('message', idleTick, false);
236
237 const animationTick = function(rafTime) {
238 isAnimationFrameScheduled = false;
packages/shared/requestAnimationFrameForReact.js
+3 -3
@@ -15,12 +15,12 @@ import warning from 'fbjs/lib/warning';
15 // We capture a local reference to any global, in case it gets polyfilled after
16 // this module is initially evaluated.
17 // We want to be using a consistent implementation.
18 -const requestAnimationFrame = global.requestAnimationFrame;
18 +const localRequestAnimationFrame = requestAnimationFrame;
19
20 if (__DEV__) {
21 if (
22 ExecutionEnvironment.canUseDOM &&
23 - typeof requestAnimationFrame !== 'function'
23 + typeof localRequestAnimationFrame !== 'function'
24 ) {
25 warning(
26 false,
@@ -30,4 +30,4 @@ if (__DEV__) {
30 }
31 }
32
33 -export default requestAnimationFrame;
33 +export default localRequestAnimationFrame;