refactor: polyfills for IE11 based on core-js

This commit is contained in:
xidedix 2018-05-01 17:42:20 +02:00
parent 1010c5b09f
commit 20770f5e02
4 changed files with 43 additions and 38 deletions

View File

@ -17,6 +17,7 @@
"bootstrap": "^4.1.0", "bootstrap": "^4.1.0",
"chart.js": "^2.7.2", "chart.js": "^2.7.2",
"classnames": "^2.2.5", "classnames": "^2.2.5",
"core-js": "^2.5.5",
"enzyme": "^3.3.0", "enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1", "enzyme-adapter-react-16": "^1.1.1",
"flag-icon-css": "^3.0.0", "flag-icon-css": "^3.0.0",

View File

@ -1,9 +1,9 @@
import './polyfill'
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import './index.css'; import './index.css';
import App from './App'; import App from './App';
import registerServiceWorker from './registerServiceWorker'; import registerServiceWorker from './registerServiceWorker';
import './polyfill'
ReactDOM.render(<App />, document.getElementById('root')); ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker(); registerServiceWorker();

View File

@ -1,42 +1,46 @@
// IE11 polyfills /*
* required polyfills
*/
import ownKeys from 'reflect.ownkeys' /** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol'
// import 'core-js/es6/object'
// import 'core-js/es6/function'
// import 'core-js/es6/parse-int'
// import 'core-js/es6/parse-float'
// import 'core-js/es6/number'
// import 'core-js/es6/math'
// import 'core-js/es6/string'
// import 'core-js/es6/date'
import 'core-js/es6/array'
// import 'core-js/es6/regexp'
import 'core-js/es6/map'
// import 'core-js/es6/weak-map'
import 'core-js/es6/set'
import 'core-js/es7/object'
const reduce = Function.bind.call(Function.call, Array.prototype.reduce); /** IE10 and IE11 requires the following for the Reflect API. */
const isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable); // import 'core-js/es6/reflect'
const concat = Function.bind.call(Function.call, Array.prototype.concat);
if (!Object.values) { /** Evergreen browsers require these. **/
Object.values = function values(O) { // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
return reduce(ownKeys(O), (v, k) => concat(v, typeof k === 'string' && isEnumerable(O, k) ? [O[k]] : []), []); // import 'core-js/es7/reflect'
};
}
if (!Object.entries) {
Object.entries = function entries(O) {
return reduce(ownKeys(O), (e, k) => concat(e, typeof k === 'string' && isEnumerable(O, k) ? [[k, O[k]]] : []), []);
};
}
if (!Array.prototype.find) {
Array.prototype.find = function(predicate) { // CustomEvent() constructor functionality in IE9, IE10, IE11
if (this == null) { (function () {
throw new TypeError('Array.prototype.find called on null or undefined');
if ( typeof window.CustomEvent === "function" ) return false
function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined }
var evt = document.createEvent( 'CustomEvent' )
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail )
return evt
} }
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
const list = Object(this);
const length = list.length >>> 0;
const thisArg = arguments[1];
let value;
for (let i = 0; i < length; i++) { CustomEvent.prototype = window.Event.prototype
value = list[i];
if (predicate.call(thisArg, value, i, list)) { window.CustomEvent = CustomEvent
return value; })()
}
}
return undefined;
};
}