Skip to content

Commit

Permalink
js: Updated code to Array.prototype.flat() and flatMap()
Browse files Browse the repository at this point in the history
  • Loading branch information
cederberg committed Dec 19, 2024
1 parent 6715fab commit be0f933
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/plugin/system/files/js/RapidContext_Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ RapidContext.Widget.isWidget = function (obj, className) {
*/
RapidContext.Widget._toCssClass = function (val) {
if (Array.isArray(val)) {
// FIXME: Use Array.prototype.flatMap(...) here
return val.map(RapidContext.Widget._toCssClass);
return val.flatMap(RapidContext.Widget._toCssClass);
} else if (val) {
return String(val).split(/\s+/g).filter(Boolean);
} else {
Expand Down Expand Up @@ -317,8 +316,7 @@ RapidContext.Widget.prototype.hasClass = function (/* ... */) {
}
}
let elem = this._styleNode();
// FIXME: Use Array.prototype.flatMap(...) here
return Array.from(arguments).map(RapidContext.Widget._toCssClass).every(isMatch);
return Array.from(arguments).flatMap(RapidContext.Widget._toCssClass).every(isMatch);
};

/**
Expand All @@ -335,8 +333,7 @@ RapidContext.Widget.prototype.addClass = function (/* ... */) {
}
}
let elem = this._styleNode();
// FIXME: Use Array.prototype.flatMap(...) here
Array.from(arguments).map(RapidContext.Widget._toCssClass).forEach(add);
Array.from(arguments).flatMap(RapidContext.Widget._toCssClass).forEach(add);
};

/**
Expand All @@ -355,8 +352,7 @@ RapidContext.Widget.prototype.removeClass = function (/* ... */) {
}
}
let elem = this._styleNode();
// FIXME: Use Array.prototype.flatMap(...) here
Array.from(arguments).map(RapidContext.Widget._toCssClass).forEach(remove);
Array.from(arguments).flatMap(RapidContext.Widget._toCssClass).forEach(remove);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/system/files/js/rapidcontext/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export function get(key, val) {
let el = path.shift();
if (el === '*' || el === '[]') {
let arrs = (el === '*') ? ctx.map(Object.values) : ctx.filter(Array.isArray);
ctx = Array.prototype.concat.apply([], arrs); // FIXME: arrs.flat()
ctx = arrs.flat();
} else {
let k = /^\[\d+\]$/.test(el) ? parseInt(el.substr(1), 10) : el;
ctx = ctx.filter(hasProperty(k)).map((o) => o[k]);
Expand Down

0 comments on commit be0f933

Please sign in to comment.