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

[dom-parts] Creation API #1010

Open
rniwa opened this issue May 2, 2023 · 3 comments
Open

[dom-parts] Creation API #1010

rniwa opened this issue May 2, 2023 · 3 comments

Comments

@rniwa
Copy link
Collaborator

rniwa commented May 2, 2023

We need to decide on the exact shape of API to create DOM parts.

Current proposal:

new ChildNodePart(node, previousSibling, nextSibling)
new AttributeNodePart(element, 'title')
@bathos
Copy link

bathos commented May 3, 2023

For ChildNodePart, the first argument would be a parent node? Would it require that previousSibling and nextSibling already be parented by that node, or would it permit them regardless of whether they are currently parented / parented by another node?

This signature is a little “forgettable” to me and I wonder if ChildNodePart wouldn’t be better off with a dictionary argument.

dictionary ChildNodePartInit {
  required Node  parentNode;
           Node? previousSibling = null;
           Node? nextSibling = null;
};

(If the parent is required to be “in agreement” with the siblings at construction time, then parentNode would not need to be required unless both siblings were null, I suppose.)

Another possibility would be something like

dictionary ChildNodePartOpts {
  Node? nextSibling = null;
  Node? previousSibling = null;
};

interface ChildNodePart {
  constructor(Node parentNode, optional ChildNodePartOpts opts = {});
  // ...
};

...which seems fairly natural if both of the “opts” options are actually optional/nullable but the parent node isn’t.

@tbondwilkinson
Copy link
Contributor

I'm interesting in particular in what happens if the nodes the ChildNodePart is referring to changes, either removed or otherwise. I'm interested in what book-keeping we expect the browser to do - is it holding onto ChildNodePart in some construct or are they only in JS?

@Jamesernator
Copy link

Jamesernator commented Jun 29, 2023

I'm interesting in particular in what happens if the nodes the ChildNodePart is referring to changes, either removed or otherwise.

Yeah this is something I've never understood with this API idea, it seems like it'd be simpler instead of the proposed ChildNodePart to do a similar thing to attributes and just have a part that sets the full list of child nodes.

i.e. If we had a template like:

<div>
   <b>Hello </b>{{name}}!
</div>

then some template parser would just generate this:

const namePart = new PartialNodeChildListPart();
const childListPart = new NodeChildListPart(divElement, [bElement, namePart, "!"]);

committing a change would effectively just be the same as setting the child list of the div. (Though internally committing would deal with the previousSibling/nextSibling stuff which it can derive from the list passed to ChildListPart).

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

4 participants