Skip to content

Commit 5ac5b5b

Browse files
committed
Update polyfill to be smarter
1 parent a5c1bc0 commit 5ac5b5b

File tree

4 files changed

+19
-65
lines changed

4 files changed

+19
-65
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ typings/
6363
# IDE
6464
.idea
6565
*.iml
66+
67+
.DS_Store

Diff for: public/index.html

+16-63
Original file line numberDiff line numberDiff line change
@@ -34,77 +34,30 @@
3434
</noscript>
3535
<script>
3636
// polyfills
37-
38-
Number.parseInt = Number.parseInt || parseInt; // IE 11
39-
Number.parseFloat = Number.parseFloat || parseFloat; // IE 11
40-
Number.isInteger = Number.isInteger || function (value) { // IE 11
41-
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
42-
};
43-
44-
// Required for material-ui/Select IE 11
45-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
46-
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
47-
if (!Array.prototype.includes) {
48-
Object.defineProperty(Array.prototype, 'includes', { // eslint-disable-line prefer-reflect,no-extend-native
49-
value: function (searchElement, fromIndex) {
50-
// 1. Let O be ? ToObject(this value).
51-
if (this == null) {
52-
throw new TypeError('"this" is null or not defined');
53-
}
54-
55-
var o = Object(this);
56-
57-
// 2. Let len be ? ToLength(? Get(O, "length")).
58-
var len = o.length >>> 0;
59-
60-
// 3. If len is 0, return false.
61-
if (len === 0) {
62-
return false;
63-
}
64-
65-
// 4. Let n be ? ToInteger(fromIndex).
66-
// (If fromIndex is undefined, this step produces the value 0.)
67-
var n = fromIndex | 0;
68-
69-
// 5. If n ≥ 0, then
70-
// a. Let k be n.
71-
// 6. Else n < 0,
72-
// a. Let k be len + n.
73-
// b. If k < 0, let k be 0.
74-
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
75-
76-
function sameValueZero (x, y) {
77-
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
78-
}
79-
80-
// 7. Repeat, while k < len
81-
while (k < len) {
82-
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
83-
// b. If SameValueZero(searchElement, elementK) is true, return true.
84-
// c. Increase k by 1.
85-
if (sameValueZero(o[k], searchElement)) {
86-
return true;
87-
}
88-
k += 1;
89-
}
90-
91-
// 8. Return false
92-
return false;
93-
}
94-
});
95-
}
96-
97-
9837
var features = [
38+
'Array.prototype.includes', // IE 11 - material-ui/Select
39+
'Number.parseInt', // IE 11
40+
'Number.parseFloat', // IE 11
9941
'Map', // IE 10
10042
'Set', // IE 10
10143
'requestAnimationFrame', // IE 9
102-
'Intl.~locale.en-CA', // IE 10, Safari 9
44+
'Intl.~locale.en-CA' // IE 10, Safari 9
10345
];
10446

10547
function missingFeatures() {
106-
return features.filter(function(f) { return !window[f.split('.')[0]] });
48+
return features.filter(function (f) {
49+
var a = f.split('.');
50+
var c = a[a.length - 1];
51+
52+
switch(a[0]) {
53+
case 'Number': return (typeof Number[c] !== 'function');
54+
case 'Array': return (typeof Array.prototype[c] !== 'function');
55+
}
56+
57+
return !window[a[0]];
58+
});
10759
}
60+
10861
var missing = missingFeatures();
10962

11063
if (missing.length) {

Diff for: src/App.js

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class App extends Component {
5959
constructor (props) {
6060
super(props);
6161
this.state = {
62-
locale: locale,
6362
isAuthenticated: false
6463
};
6564
}

Diff for: src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom';
23

34
import App from './App';
4-
import ReactDOM from 'react-dom';
55

66
ReactDOM.render((<App/>), document.getElementById('root'));

0 commit comments

Comments
 (0)