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
Situation 2: writing utility function for updating a path
functionincrement(record, ...path){// even a 'simple' implementation is ~10 lines before adding error checksassert(path.length>0);let[prop, ...rest]=path;if(rest.length===0){return{
...record,[prop]: record[prop]+1}}return{
...record,[prop]: increment(record[prop], ...rest)}}
Idea: Add syntax for dynamic paths
If a value could be used as a path then it can be reused and passed around. An array of string/number keys could be used for such a value. Above examples become:
There are at least two situations where needing to specify the path literally can be frustrating:
Situation 1: Mutating deep path based on current value
Situation 2: writing utility function for updating a path
Idea: Add syntax for dynamic paths
If a value could be used as a path then it can be reused and passed around. An array of string/number keys could be used for such a value. Above examples become:
Alternative: Add static helper
Alternatively this type of update could be added to the global
Record
object. Something likeRecord.update(record, path, update)
.The text was updated successfully, but these errors were encountered: