feat!: Multiple tree support #655
Draft
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.
Adds support for nested trees to the schema and all existing adapters.
Tree updates must now include the
tree_idfield which indicates to which tree this update applies. The main tree is identified byTreeId::ROOT. Subtrees have to use an UUID (preferrably version 4 to avoid collisions between trees from different sources). The common crate re-exports theUuidtype from the uuid crate, but users will have to enable extra features on the uuid crate in order to generate UUIDs.Graft nodes are nodes which host a subtree. They are defined by setting
Node::tree_idon them. Graft nodes cannot have regular children. They can point to a subtree that does not exist yet. When a graft node is removed or itstree_idproperty is cleared, its subtree is removed unless another graft node is provided as part of the same update, in which case the subtree is reparented.The keyboard focus is now determined by starting at the root of the main tree: if the tree-local focus point to a regular node then this node gets the focus, otherwise if the node is a graft then search continues into the subtree.
ActionRequestnow usestarget_nodeandtarget_treeto indicate on which node to apply an action.Internally, adapters now refer to nodes using a combination of local node ID (provided by the user in tree updates) and tree index. Tree indices are 32 bit unsigned integers that map to
TreeIds.Prior art
In the past we used to use
NonZeroU128as ID for nodes in the schema. We switched tou64as it's easier to work with in other programming languages and for serialization. However UUIDs are well established and in fact schemars has support for them so this should be less of an issue.Chromium does not allow nodes to refer to nodes in different trees so it is not possible, for instance, to indicate that a node is labelled by another node that is in a different tree. The same applies here. I don't think it is that useful in practice and it would add a lot of complexity.
Alternative to #641
This design fits into the existing schema and adapter model rather than building on top of it, no conditional compilation required to work with every adapter. It should also be more flexible around tree identification, hopefully allowing completely independant providers to expose their subtree(s) without a central registrar.