Adding map functions to Node and Fragment #85
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "willisjtc/add-map-functions-to-node"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adding map functions to be able to map over children nodes in the Node and Fragment classes.
The impetus for this is if you want to modify the child nodes in a non mutation way, you need to call
forEachon aNodeand push those Node's onto an array, and then make your modifications to those child nodes. The same goes for fragments.The documentation in Fragment even states:
This way, instead of using
forEachwe can just map over child nodes and get a new object in return. I think this also provides a cleaner way to make non-mutative changes in a syntactically cleaner style.I didn't create an RFC just because it's a minor change.
I think that this kind of simple utility is best implemented locally in the codebase that needs it. There's a ton of possible variants (that allow deleting nodes, adding nodes, that check content rules, that automatically merge adjacent text nodes, etc) and I don't want to grow the interface on these classes too much.
Pull request closed