Skip to content

Commit

Permalink
Added a fallback Array.prototype.flat implementation (#935)
Browse files Browse the repository at this point in the history
Fixes #647.

Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
  • Loading branch information
crnjan authored and ghys committed Apr 18, 2021
1 parent cd72f91 commit 2142c8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bundles/org.openhab.ui/web/src/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './compatibility'

// Import Vue
import Vue from 'vue'

Expand Down
9 changes: 9 additions & 0 deletions bundles/org.openhab.ui/web/src/js/compatibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

if (!Array.prototype.flat) {
// eslint-disable-next-line no-extend-native
Array.prototype.flat = function (depth = 1) {
return this.reduce(function (flat, toFlatten) {
return flat.concat((Array.isArray(toFlatten) && (depth > 1)) ? toFlatten.flat(depth - 1) : toFlatten)
}, [])
}
}

0 comments on commit 2142c8e

Please sign in to comment.