fork-tongue / collagraph

Collagraph 📓 Reactive user interfaces
MIT License
30 stars 1 forks source link

Use index instead of anchor for Renderer.insert function #10

Open berendkleinhaneveld opened 2 years ago

berendkleinhaneveld commented 2 years ago

I want to propose to change the API of Renderer.insert to take an optional position instead of an anchor object. This might simplify the reconciliation code a bit and save some computations (both in reconciliation and commit phases).

The API was just copied/inspired by Vue's custom renderer API, but using an anchor instead of an index makes things awfully complicated... I guess Vue choose this API because of JavaScript's insertBefore(), but we don't necessarily need it ourselves? Inserting items in PySide/Qt works with indices and the API for Pygfx can be easily updated to work with indices instead as well.

Korijn commented 2 years ago

I mean.. go right ahead. Depending on what's easiest for you, you can also consider supporting both; the anchor can be None, an index, or an anchor object.