widgetti / ipyreact

React for ipywidgets that just works. No webpack, no npm, no hassle
BSD 3-Clause "New" or "Revised" License
104 stars 8 forks source link

refactor!: make widget composable by allowing children #52

Closed maartenbreddels closed 4 months ago

maartenbreddels commented 6 months ago

BREAKING CHANGE: this is a breaking change because of renaming set_value to setValue on the frontend side.

This commit makes several changes, instead of having a single ReactWidget we now have a Widget (with no default value trait) and a ValueWidget (with a default value trait).

Furthermore, by specificing _module and _type instead of _esm we can now render any React component from any ES module, or even standard html components like

or .

The main (wrapper) component is now created in the model, which makes it easier to obtain the components of children. Once the main wrapper component is created, the while children tree is also resolved, and a synchroneous render can be made in one go.

TODO

  • [x] update docs
  • [x] avoid rendering twice by passing a ref down the component tree (and children) so that the root view can be passed down to the save_changes (needed for the print output to go to the right notebook cell)