Add Object.values() & Object.entries() to FilterExpressions
Categories
(Firefox :: Messaging System, task, P2)
Tracking
()
People
(Reporter: aminomancer, Unassigned)
References
(Blocks 1 open bug)
Details
Right now we have a JEXL transform for Object.keys()
in FilterExpressions.sys.mjs, but no Object.values()
. This would give us some good new abilities, like asserting that at least one child object in a keyed object like addonsInfo.addons
has a given value. For example:
// hasInstalledAtLeastOneAddon
// in javascript
Object.values(addonsInfo.addons).some(
addon => addon.type == "extension" && !addon.isSystem
)
// in jexl
addonsInfo.addons|values[.type == "extension" && !.isSystem] | length > 0
I believe this is impossible right now. You can use mapToProperty
to map an array of objects to an array of values. But if your objects are keyed properties of an object, as is the case for addonsInfo
, then all you can do is manually check by known IDs, or get an array of IDs with Object.keys()
and manually check by index of that array. So there's no good way to do it now, unless I'm missing something. Here's the current structure.
Alternatively, we could just avoid having objects with large numbers of keys as targeting values. This value could be expressed as an array, where instead of keys the addon IDs are simply id
properties of the member objects. But then we'd need to remember this issue moving forward to avoid reintroducing it with another attribute. I like adding values
and entries
since it's more of a "set it and forget it" approach, and it incidentally expands our targeting capabilities in general.
Since we'd have both keys and values, it seems silly not to have entries also. So, for the sake of completeness, I'd add that one too.
Reporter | ||
Updated•1 year ago
|
Description
•