Replies: 1 comment 1 reply
-
Thanks for your patience in my response (working on my thesis these days). I think this is something that is baked into Backbone's API, which we inherited for initial compatibility. Fortunately (and unfortunately) the anywidget API is narrower, which gives us more space to fix these things or make better behavior.... but it seems we currently lack the backbone APIs that allowed you to get around this previously. I'd really like to avoid adding new backbone-based APIs/semantics and instead focus on better APIs that have the behavior that end users expect. I think we have the capabilities to cut ourselves away from this API, but it will take me a little time to think through and implement.
These two PRs I have staged but just haven't had the time to push forward because I want to be very clear with messaging to the community and there will be subtle breaking changes for some advanced anywidget develoeprs. For current wor arounds, I'll need to consider some alternatives and get back to you. I'm sorry I don't have a different answer right now! |
Beta Was this translation helpful? Give feedback.
-
A widget's data might call for using a list of dicts to represent some objects that we want to manipulate (like a list of bounding boxes on an image). But using this type of data has some issues in syncing the changes from js to python.
The issue is demonstrated by the example widget below. Its value is a list of numbers represented by dicts like
{'n': 1}
. It also has two buttons - one adds a new dict and another one edits an existing dict. If you run this widget in a jupyter notebook and press the buttons a few times you will notice that only the "Add another number" button causes changes to the displayed array. The changes made by "Increment first number" button are remembered internally but the model change event for them doesn't fire. You will only see the incremented number once you add another one with the "Add" button. Value on the python side is also blind to item edits - same as the displayed array.The difference between two buttons seems to be that one changes array length and the other one doesn't. So one workaround I've found is to set the value to an empty array right before setting it to the actual edited value - see the commented line in
incrementButton
's click handler. This probably makes it seem like array length changed so the change event fires for the edit and everything works as expected.What I would like to discuss:
Beta Was this translation helpful? Give feedback.
All reactions