Skip to content

Commit

Permalink
Merge pull request #13246 from CedricGuillemet/arrayFlatPolyfill
Browse files Browse the repository at this point in the history
array flat polyfill for Chakra
  • Loading branch information
sebavan authored Nov 15, 2022
2 parents 85a8e70 + c1e367d commit afe5eb4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/dev/core/src/Engines/nativeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,31 @@ export class NativeEngine extends Engine {
};
}

// polyfill for Chakra
if (!Array.prototype.flat) {
Object.defineProperty(Array.prototype, "flat", {
configurable: true,
value: function flat() {
const depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]);

return depth
? Array.prototype.reduce.call(
this,
function (acc: any, cur: any) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1));
} else {
acc.push(cur);
}
return acc;
},
[]
)
: Array.prototype.slice.call(this);
},
writable: true,
});
}
// Currently we do not fully configure the ThinEngine on construction of NativeEngine.
// Setup resolution scaling based on display settings.
const devicePixelRatio = window ? window.devicePixelRatio || 1.0 : 1.0;
Expand Down

0 comments on commit afe5eb4

Please sign in to comment.