Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array flat polyfill for Chakra #13246

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
array flat polyfill for Chakra
  • Loading branch information
CedricGuillemetMS committed Nov 15, 2022
commit c1e367d1a13f00ae7a0a6066d0ff462456048394
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