You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed a pattern of wanting to remove falsy values from objects, but there's no elegant way of doing that:
constreducer=[input=>{// get the "a" and "b" properties, but only if they're truthy// this works, but it's awkward and boilerplate-ishconstresult={}if(obj.a)result.a=aif(obj.b)result.b=breturnobj}]
Suggested solution:
I don't know, but these are a few ideas:
Proposal # 1
constreducer={'?a': '$a',// only include this if "$a" is truthyb: '$b'}
This works, but we removed the special treatment for keys beginning with '$', so this feels like going backward.
Proposal # 2
// not the best name...const{ removeFalsy }=DataPoint.helpersremoveFalsy({a: '$a',b: '$b'})
This would remove every falsy value, but we might want to keep some of them.
Proposal # 3
// another not-so-great name...const{ truthy }=DataPoint.helpers{a: truthy('$a'),b: '$b'}
It could work? Feels weird though...
Summary
It would be nice if we don't add a new reducer helper, especially because it would only be useful for object reducers. Not sure if there's a good solution though!
The text was updated successfully, but these errors were encountered:
Problem description:
I've noticed a pattern of wanting to remove falsy values from objects, but there's no elegant way of doing that:
Suggested solution:
I don't know, but these are a few ideas:
Proposal # 1
This works, but we removed the special treatment for keys beginning with
'$'
, so this feels like going backward.Proposal # 2
This would remove every falsy value, but we might want to keep some of them.
Proposal # 3
It could work? Feels weird though...
Summary
It would be nice if we don't add a new reducer helper, especially because it would only be useful for object reducers. Not sure if there's a good solution though!
The text was updated successfully, but these errors were encountered: