Jupyter4Science / scipy23-jupyter-web-app-tutorial

A 4-hour tutorial entitled "How the Little Jupyter Notebook Became a Web App: Managing Increasing Complexity with nbdev" presented at SciPy 2023 in Austin, TX.
https://cfp.scipy.org/2023/talk/NFWZXD/
Apache License 2.0
6 stars 4 forks source link

Should traitlets be used in the model? #13

Closed nicole-brewer closed 1 year ago

nicole-brewer commented 1 year ago

For Superpower, I remember that for some reason, I didn't use traitlets in the model. For the same reason I didn't use linking I think. I can't remember why. I'm not sure if I wrote it down in one of my papers somewhere? ... Yes. This following is from Benefits and Limitations of Using Jupyter Notebooks:

This component is highly interactive, meaning that user manipulations of any of the internal IntText widgets required a cascade of updates to the Model, which in turn needed to be reflected in the widgets on the perimeter. Unfortunately, the traitlets library doesn’t support container traits such as arrays. This means that when an element in a list or numpy array is updated, it doesn’t trigger an event. One work-around would have been to not completely ex- tricate the Model from the Delegate, and to combine the logic and the view together in a single component. This does not work for our use case because we needed to pass each Model through several Delegates, so concerns had to be purely separated. Separating concerns is best practice, especially if applications are expected to grow in complexity. Another solution might have been to have many individual Int traits in the Model to represent each IntText in the UI. This might be reasonable depending on how many Grid elements their were. For example, you could represent a 2x2 grid with four Ints instead of a 2x2 numpy array. This wasn’t an option for us, because the size of the grid was dynamic. A user could chose a 2x2 grid or a 3x5 grid so there was no way to hard code these integers. Therefore, we needed to be able to observe a change in an array, which is something that traitlets doesn’t support out of the box.

So the takeaway here is that I'm free to use traitlets and link traits