Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depth of the currently traversed element in constant time #94

Open
mgoldenbe opened this issue Oct 31, 2021 · 3 comments
Open

Depth of the currently traversed element in constant time #94

mgoldenbe opened this issue Oct 31, 2021 · 3 comments

Comments

@mgoldenbe
Copy link

mgoldenbe commented Oct 31, 2021

Can I access the depth of the currently traversed (e.g. during the depth-first walk) element in constant time? Right now, the only way of getting the depth that I see (besides storing it with the node) is by calling getPath:

root.walk(el => {console.log(el.model.id, el.getPath().length);})

@mgoldenbe mgoldenbe changed the title Access to current depth during the walk Depth of the currently traversed element Oct 31, 2021
@mgoldenbe mgoldenbe changed the title Depth of the currently traversed element Depth of the currently traversed element in constant time Oct 31, 2021
@joaonuno
Copy link
Owner

joaonuno commented Nov 1, 2021

You're right, that's the only way as of now and it's not constant time as you noted. I'll leave this open because it seems a nice improvement for a future version.

@coreymunn3
Copy link

Wow, if it weren't for this issue I wouldn't have even know that getting depth was possible using this library, or that you even get something with a "getPath" method on it. The documentation here is painfully inadequate.

@joaonuno
Copy link
Owner

Hi, getPath is documented here and there's an example on the lib's page:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants