From 20770f5e02240e771c003d97f974f59a61fef4ed Mon Sep 17 00:00:00 2001 From: xidedix Date: Tue, 1 May 2018 17:42:20 +0200 Subject: [PATCH] refactor: polyfills for IE11 based on `core-js` --- package.json | 1 + src/index.js | 2 +- src/polyfill.js | 76 ++++++++++++----------- src/views/Base/Breadcrumbs/Breadcrumbs.js | 2 +- 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index abee828..aab1720 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 74dea6e..d3f2c9c 100644 --- a/src/index.js +++ b/src/index.js @@ -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(, document.getElementById('root')); registerServiceWorker(); diff --git a/src/polyfill.js b/src/polyfill.js index ee7f8ad..a0dd12c 100644 --- a/src/polyfill.js +++ b/src/polyfill.js @@ -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 +})() diff --git a/src/views/Base/Breadcrumbs/Breadcrumbs.js b/src/views/Base/Breadcrumbs/Breadcrumbs.js index 888aabe..af3a2cc 100644 --- a/src/views/Base/Breadcrumbs/Breadcrumbs.js +++ b/src/views/Base/Breadcrumbs/Breadcrumbs.js @@ -44,4 +44,4 @@ class Breadcrumbs extends Component { } } -export default Breadcrumbs; \ No newline at end of file +export default Breadcrumbs;