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",
"chart.js": "^2.7.2",
"classnames": "^2.2.5",
"core-js": "^2.5.5",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"flag-icon-css": "^3.0.0",

View File

@ -1,9 +1,9 @@
import './polyfill'
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import './polyfill'
ReactDOM.render(<App />, document.getElementById('root'));
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);
const isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable);
const concat = Function.bind.call(Function.call, Array.prototype.concat);
/** IE10 and IE11 requires the following for the Reflect API. */
// import 'core-js/es6/reflect'
if (!Object.values) {
Object.values = function values(O) {
return reduce(ownKeys(O), (v, k) => concat(v, typeof k === 'string' && isEnumerable(O, k) ? [O[k]] : []), []);
};
}
/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
// 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) {
if (this == null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
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++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
// CustomEvent() constructor functionality in IE9, IE10, IE11
(function () {
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
}
CustomEvent.prototype = window.Event.prototype
window.CustomEvent = CustomEvent
})()

View File

@ -44,4 +44,4 @@ class Breadcrumbs extends Component {
}
}
export default Breadcrumbs;
export default Breadcrumbs;