solid icon indicating copy to clipboard operation
solid copied to clipboard

Pass previous node in universal insertNode

Open ranfdev opened this issue 3 years ago • 3 comments

Describe the bug

I've just implemented a custom renderer to GTK4, using solid-js/universal. It works pretty well, even though it requires some little workarounds.

Gtk.Box, which is one of the most used GTK widgets, has a method insert_child_after(child, previous_sibling), while solid's universal insertNode only provides the sibling after: From the solid universal renderer example:

insertNode(parent, node, anchor) {
    parent.insertBefore(node, anchor);
},

what GTK requires me to do:

insertNode(parent, node, anchor) {
    parent.insert_child_after(node, ???????);
},

Steps to Reproduce the Bug or Issue

Implement a custom native renderer using gtk

Expected behavior

I think solid may already have the information about the previous_sibling internally. If that's the case, it would be nice exposing that sibling in insertNode so that people can write

insertNode(parent, node, next_sibling, prev_sibling) {
    parent.insert_child_after(node, prev_sibling);
}

I think I'm able to workaround this issue for many GTK widgets, but having the prev_sibling directly available would be nicer

ranfdev avatar Aug 08 '22 12:08 ranfdev

Ok interesting. I just copied the DOM APIs which meant we used same reconciler and same methods. It may be possible as you say. In the DOM if you don't have an anchor, like it is null, it inserts it at the end. And the parent is aware of their children so it can do that.

ryansolid avatar Aug 08 '22 18:08 ryansolid