mavoweb / vastly

Everything you need to support a custom formula language

Home Page:https://vastly.mavo.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`walk` should pass property and index into callback

adamjanicki2 opened this issue · comments

We need to be able to access the property and index of a child relative to its parent from walk when building out #43

Currently, when walk calls its callback, it does it like so: callback(node, property, parent). Instead, I’m proposing we tweak it to be called like so: callback(node, {node: parent, property, index}). In addition to being more broadly useful, it would allow parents.setAll to call the new version of parents.set which requires knowledge of property and index

Could you please elaborate? I don't understand what you mean or why that's needed from that one sentence.

Just updated issue 👍

@LeaVerou does the new description make more sense?

Currently, when walk calls its callback, it does it like so: callback(node, property, parent). Instead, I’m proposing we tweak it to be called like so: callback(node, {node: parent, property, index}). In addition to being more broadly useful, it would allow parents.setAll to call the new version of parents.set which requires knowledge of property and index

Agreed. And putting them all into an object like that means we can directly pass the object around.

I suggest we establish this as a "Path" concept and use this terminology consistently across the codebase, e.g. that parameter name would be called parentPath. What do you think?

(I'm unsure if "path" is the best name, but I feel "details" is too generic, and we do need a consistent concept for this)

How about we go with path for now? It's pretty descriptive about what it's saying -- a link between a child/parent or parent/child. It's also nice that it could generalize to being a path of length > 1 if that is needed in the future

When I hear path I think of files.
Maybe trail would suit?

When I hear path I think of files. Maybe trail would suit?

When I hear trail I think of hiking trails.

Every common word is bound to have a wide set of associations, but "path" is also used by JSONPath in the same way, and by XPath for elements.