Skip to content

Commit d0a614c

Browse files
author
Josh Crowther
authored
Porting Polyfills Fix (missing in master) (#668)
* Fix polyfills for fetch * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * Removing legacy file
1 parent ca57c4d commit d0a614c

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2018 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import './promise';
18+
import { global } from './global';
19+
20+
(self => {
21+
require('whatwg-fetch');
22+
})(global);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2018 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const __global = (() => {
18+
if (typeof global !== 'undefined') {
19+
return global;
20+
}
21+
if (typeof window !== 'undefined') {
22+
return window;
23+
}
24+
if (typeof self !== 'undefined') {
25+
return self;
26+
}
27+
throw new Error('unable to locate global object');
28+
})();
29+
30+
export const global = __global;

packages/polyfill/src/polyfills/promise.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
const __global = (() => {
18-
if (typeof global !== 'undefined') {
19-
return global;
20-
}
21-
if (typeof window !== 'undefined') {
22-
return window;
23-
}
24-
if (typeof self !== 'undefined') {
25-
return self;
26-
}
27-
throw new Error('unable to locate global object');
28-
})();
17+
import { global } from './global';
2918

3019
// Polyfill Promise
3120
if (typeof Promise === 'undefined') {
3221
// HACK: TS throws an error if I attempt to use 'dot-notation'
33-
__global['Promise'] = require('promise-polyfill') as PromiseConstructor;
22+
global['Promise'] = require('promise-polyfill') as PromiseConstructor;
3423
}

0 commit comments

Comments
 (0)