Skip to content

Commit 20770f5

Browse files
committed
refactor: polyfills for IE11 based on core-js
1 parent 1010c5b commit 20770f5

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"bootstrap": "^4.1.0",
1818
"chart.js": "^2.7.2",
1919
"classnames": "^2.2.5",
20+
"core-js": "^2.5.5",
2021
"enzyme": "^3.3.0",
2122
"enzyme-adapter-react-16": "^1.1.1",
2223
"flag-icon-css": "^3.0.0",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import './polyfill'
12
import React from 'react';
23
import ReactDOM from 'react-dom';
34
import './index.css';
45
import App from './App';
56
import registerServiceWorker from './registerServiceWorker';
6-
import './polyfill'
77

88
ReactDOM.render(<App />, document.getElementById('root'));
99
registerServiceWorker();

src/polyfill.js

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
// IE11 polyfills
2-
3-
import ownKeys from 'reflect.ownkeys'
4-
5-
const reduce = Function.bind.call(Function.call, Array.prototype.reduce);
6-
const isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable);
7-
const concat = Function.bind.call(Function.call, Array.prototype.concat);
8-
9-
if (!Object.values) {
10-
Object.values = function values(O) {
11-
return reduce(ownKeys(O), (v, k) => concat(v, typeof k === 'string' && isEnumerable(O, k) ? [O[k]] : []), []);
12-
};
13-
}
14-
15-
if (!Object.entries) {
16-
Object.entries = function entries(O) {
17-
return reduce(ownKeys(O), (e, k) => concat(e, typeof k === 'string' && isEnumerable(O, k) ? [[k, O[k]]] : []), []);
18-
};
19-
}
20-
21-
if (!Array.prototype.find) {
22-
Array.prototype.find = function(predicate) {
23-
if (this == null) {
24-
throw new TypeError('Array.prototype.find called on null or undefined');
25-
}
26-
if (typeof predicate !== 'function') {
27-
throw new TypeError('predicate must be a function');
28-
}
29-
const list = Object(this);
30-
const length = list.length >>> 0;
31-
const thisArg = arguments[1];
32-
let value;
33-
34-
for (let i = 0; i < length; i++) {
35-
value = list[i];
36-
if (predicate.call(thisArg, value, i, list)) {
37-
return value;
38-
}
39-
}
40-
return undefined;
41-
};
42-
}
1+
/*
2+
* required polyfills
3+
*/
4+
5+
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
6+
// import 'core-js/es6/symbol'
7+
// import 'core-js/es6/object'
8+
// import 'core-js/es6/function'
9+
// import 'core-js/es6/parse-int'
10+
// import 'core-js/es6/parse-float'
11+
// import 'core-js/es6/number'
12+
// import 'core-js/es6/math'
13+
// import 'core-js/es6/string'
14+
// import 'core-js/es6/date'
15+
import 'core-js/es6/array'
16+
// import 'core-js/es6/regexp'
17+
import 'core-js/es6/map'
18+
// import 'core-js/es6/weak-map'
19+
import 'core-js/es6/set'
20+
import 'core-js/es7/object'
21+
22+
/** IE10 and IE11 requires the following for the Reflect API. */
23+
// import 'core-js/es6/reflect'
24+
25+
/** Evergreen browsers require these. **/
26+
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
27+
// import 'core-js/es7/reflect'
28+
29+
30+
31+
// CustomEvent() constructor functionality in IE9, IE10, IE11
32+
(function () {
33+
34+
if ( typeof window.CustomEvent === "function" ) return false
35+
36+
function CustomEvent ( event, params ) {
37+
params = params || { bubbles: false, cancelable: false, detail: undefined }
38+
var evt = document.createEvent( 'CustomEvent' )
39+
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail )
40+
return evt
41+
}
42+
43+
CustomEvent.prototype = window.Event.prototype
44+
45+
window.CustomEvent = CustomEvent
46+
})()

src/views/Base/Breadcrumbs/Breadcrumbs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ class Breadcrumbs extends Component {
4444
}
4545
}
4646

47-
export default Breadcrumbs;
47+
export default Breadcrumbs;

0 commit comments

Comments
 (0)