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

Config option for how to get parents #30

Open
LeaVerou opened this issue Apr 1, 2024 · 0 comments
Open

Config option for how to get parents #30

LeaVerou opened this issue Apr 1, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@LeaVerou
Copy link
Member

LeaVerou commented Apr 1, 2024

There are many tree implementations that are already doing their own parent pointers. For example, in DOM nodes, you can always get to the parent via node.parentNode. We should have a config option for this so we don't end up doing duplicate work and introducing unnecessary error conditions.

This could be a config option (which also becomes a Treecle instance property). For treecle to properly use this, it needs to know both how to read parents, and set parents.

Strawman: A parent property whose value is either a string (read/write property name) or a { get: function(node), set: function(node, otherNode) } for more elaborate schemas.

For example, for the DOM, this could look like this:

parent: {
	get: n => n.parentNode,
	set: (node, newParent) => newParent.append(node);
}

I'm not convinced this is a good design: what if we need to specify where exactly the node gets appended? Not to mention this affects other properties too.

Perhaps it should be possible to just say parent: "parentNode" and just error if we try to use any properties that require writing parents. Or even have an option to turn that off and fail silently (since the tree may automatically handle that).

People should be able to use treecle for read-only stuff like walk() or closest() or getting complex familial relationships without having to also use its parent mgmt system (or have to implement complex parent setting helpers they don't need just to provide a value to parent.set).

@LeaVerou LeaVerou added the enhancement New feature or request label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant