upgrade descendants and nodesBetween handlers to support aborting a graph scan#75
Open
st3v0 wants to merge 1 commit intoProseMirror:masterfrom
Open
upgrade descendants and nodesBetween handlers to support aborting a graph scan#75st3v0 wants to merge 1 commit intoProseMirror:masterfrom
st3v0 wants to merge 1 commit intoProseMirror:masterfrom
Conversation
…canning the graph if the handler returns something other then void | boolean
Member
|
What I've been doing is just setting a flag (or storing a non-null result) when the search has finished, and putting a check for that at the top of the callback, making it return false right away. That seems to cover the cases where this is necessary with less complication. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
We need the ability to end the recursive scan (part way through the graph) which is performed by
descendantsandnodesBetween.At the moment if we return
falsefrom the node handler; the scan continues to the next sibling in the graph. This is wasteful if there is a large amount of siblings and all we're trying to do is check if a node exists.Proposed Solution
We could modify the
nodesBetweennode handler method to support more than returningboolean | void. If anything else is returned then the scan stops and returns that item.This is a performance improvement solution with the added benefit of being able to use it for finding.
Checklist
Is this solution backwards compatible: ✅
Does this solution include tests: ❌
Examples
Say you want to get a text node from somewhere in the doc, which contains the text 'foobar', you could;
Or you want to get the type of the first leaf node;