mavoweb / treecle

WIP. A toolbox for hierarchical JS objects.
https://treecle.mavo.io
MIT License
7 stars 0 forks source link

convert paths to arrays #16

Closed adamjanicki2 closed 8 months ago

adamjanicki2 commented 8 months ago

Converts all paths to arrays and closes #6

netlify[bot] commented 8 months ago

Deploy Preview for treecle ready!

Name Link
Latest commit 8c0013873f07a9bc1f7ab4693f6b39c2df42c563
Latest deploy log https://app.netlify.com/sites/treecle/deploys/65e77db14ff0e50008a4ca3c
Deploy Preview https://deploy-preview-16--treecle.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

LeaVerou commented 8 months ago

Just pushed two util methods to help you do this!

(Have not tested them, feel free to make any changes needed)

adamjanicki2 commented 8 months ago

Just pushed two util methods to help you do this!

(Have not tested them, feel free to make any changes needed)

Just thinking here -- do we want to export the get helper to authors? I think it would be useful. We could stick it in path.js along with a function that finds the path between two nodes. The set helper should remain private since it becomes complicated with parent pointers and pretty much only works when we use it internally within a function like this

LeaVerou commented 8 months ago

Just pushed two util methods to help you do this! (Have not tested them, feel free to make any changes needed)

Just thinking here -- do we want to export the get helper to authors? I think it would be useful. We could stick it in path.js along with a function that finds the path between two nodes. The set helper should remain private since it becomes complicated with parent pointers and pretty much only works when we use it internally within a function like this

Not sure what you mean, these are already exported and they can import them?

adamjanicki2 commented 8 months ago

I think a lot of this still assumes a shallow path. Try to use your code with cases where to get from each node to each children you have to follow something like foo.bar.baz. I haven't looked super closely, but from a first skim, I don't think it would work.

Would this even be allowed? In what cases could you follow two object properties and get to a child? In the case of foo.bar.baz, how could baz be a direct child of foo?

adamjanicki2 commented 8 months ago

@LeaVerou my thinking was we sort of have to enforce the fact that children can only be accessed via a property, or a property and an index in the case of an array; otherwise having arbitrary ways of accessing children would defeat the purpose of distinguishing between children and descendants

LeaVerou commented 8 months ago

What’s the point of making the path an array then?

adamjanicki2 commented 8 months ago

What’s the point of making the path an array then?

@LeaVerou For the future when we implement paths between arbitrary nodes, which have n edges between each other. Although parents/children will always have either 1 or 2 keys between them, making it an array standardizes our concept of a path