From 3d8167e135524daa0d67493532910cd47359b8a6 Mon Sep 17 00:00:00 2001 From: Sergey Zavgorodniy Date: Mon, 19 Dec 2016 18:04:59 +0300 Subject: [PATCH 1/3] Fix enumerable array polyfill --- src/utils/polyfill.js | 85 ++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/src/utils/polyfill.js b/src/utils/polyfill.js index 6cbcafa..62cfc0d 100644 --- a/src/utils/polyfill.js +++ b/src/utils/polyfill.js @@ -1,38 +1,63 @@ -/** - * Array.prototype.find() - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find - */ -(function() { - function polyfill(fnName) { - if (!Array.prototype[fnName]) { - Array.prototype[fnName] = function(predicate /*, thisArg */ ) { - var i, len, test, thisArg = arguments[1]; - - if (typeof predicate !== "function") { - throw new TypeError(); +(function () { + /** + * Array.prototype.find() + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find + */ + if (!Array.prototype.find) { + Object.defineProperty(Array.prototype, 'find', { + value: function (predicate) { + 'use strict'; + if (this == null) { + throw new TypeError('Array.prototype.find called on null or undefined'); } - - test = !thisArg ? predicate : function() { - return predicate.apply(thisArg, arguments); - }; - - for (i = 0, len = this.length; i < len; i++) { - if (test(this[i], i, this) === true) { - return fnName === "find" ? this[i] : i; - } + if (typeof predicate !== 'function') { + throw new TypeError('predicate must be a function'); } + var list = Object(this); + var length = list.length >>> 0; + var thisArg = arguments[1]; + var value; - if (fnName !== "find") { - return -1; + for (var i = 0; i < length; i++) { + value = list[i]; + if (predicate.call(thisArg, value, i, list)) { + return value; + } } - }; - } + return undefined; + } + }); } + /** + * Array.prototype.findIndex() + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex + */ + if (!Array.prototype.findIndex) { + Object.defineProperty(Array.prototype, 'findIndex', { + value: function (predicate) { + 'use strict'; + if (this == null) { + throw new TypeError('Array.prototype.findIndex called on null or undefined'); + } + if (typeof predicate !== 'function') { + throw new TypeError('predicate must be a function'); + } + var list = Object(this); + var length = list.length >>> 0; + var thisArg = arguments[1]; + var value; - for (var i in { - find: 1, - findIndex: 1 - }) { - polyfill(i); + for (var i = 0; i < length; i++) { + value = list[i]; + if (predicate.call(thisArg, value, i, list)) { + return i; + } + } + return -1; + }, + enumerable: false, + configurable: false, + writable: false + }); } }()); From c602a304cfe5390778c4446c42e0afd6a6b22844 Mon Sep 17 00:00:00 2001 From: Sergey Zavgorodniy Date: Mon, 19 Dec 2016 18:48:46 +0300 Subject: [PATCH 2/3] Fix object assign error in InternetExlorer by polyfill --- src/utils/polyfill.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/utils/polyfill.js b/src/utils/polyfill.js index 62cfc0d..4adf34e 100644 --- a/src/utils/polyfill.js +++ b/src/utils/polyfill.js @@ -60,4 +60,32 @@ writable: false }); } + /** + * Object.assign() + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign + */ + if (typeof Object.assign != 'function') { + Object.assign = function (target, varArgs) { // .length of function is 2 + 'use strict'; + if (target == null) { // TypeError if undefined or null + throw new TypeError('Cannot convert undefined or null to object'); + } + + var to = Object(target); + + for (var index = 1; index < arguments.length; index++) { + var nextSource = arguments[index]; + + if (nextSource != null) { // Skip over if undefined or null + for (var nextKey in nextSource) { + // Avoid bugs when hasOwnProperty is shadowed + if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { + to[nextKey] = nextSource[nextKey]; + } + } + } + } + return to; + }; + } }()); From bbf04506e9fa5eeb6e4562c79ea58853e18c3e0e Mon Sep 17 00:00:00 2001 From: Sergey Zavgorodniy Date: Thu, 22 Dec 2016 15:12:58 +0300 Subject: [PATCH 3/3] Change redundant ES6 Map() to Object for IE10 compatibility --- src/components/body/StyleTranslator.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/body/StyleTranslator.js b/src/components/body/StyleTranslator.js index 9b7c7fb..571ae46 100644 --- a/src/components/body/StyleTranslator.js +++ b/src/components/body/StyleTranslator.js @@ -8,7 +8,7 @@ export class StyleTranslator{ constructor(height){ this.height = height; - this.map = new Map(); + this.map = {}; } /** @@ -17,8 +17,8 @@ export class StyleTranslator{ */ update(rows){ let n = 0; - while (n <= this.map.size) { - let dom = this.map.get(n); + while (n <= Object.keys(this.map).length) { + let dom = this.map[n]; let model = rows[n]; if(dom && model){ TranslateXY(dom[0].style, 0, model.$$index * this.height); @@ -33,7 +33,7 @@ export class StyleTranslator{ * @param {dom} dom */ register(idx, dom){ - this.map.set(idx, dom); + this.map[idx] = dom; } }