-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC: Refactor react #308
base: main
Are you sure you want to change the base?
POC: Refactor react #308
Conversation
Thanks for the PR! Could you try if adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks interesting, and agree it would simplify a lot of boilerplate code! I can't fully wrap my head around some of the aspects at the moment, in particular the calls to use_echo_state without return values and what side effects that has - could you clarify this a little?
@@ -1,148 +0,0 @@ | |||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though the new code is much more concise, could you maybe keep the separation between files of the layer artist and viewer and so on? (just as it is a pretty common pattern I have been using for viewers so I find it easier to navigate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
def calculate_bins( | ||
viewer_state: HistogramViewerState, layer_state: HistogramLayerState | ||
): | ||
use_echo_state(viewer_state, "hist_x_max") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What effect does this line have in practice as no return value is being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is the 'magic' from react, combined with having 2 places to store the state. The idea is that if you use use_echo_state
, your 'render function' (i.e. the function wrapped in @react.component) will be re-executed. Typically, you'd use the return value, but they are also directly accessible using e.g. viewer_state.normalize
etc.
af99bf0
to
04148fb
Compare
This is a proof of concept of applying https://github.com/widgetti/react-ipywidgets to glue-jupyter.
#273 was the inspiration to develop react-ipywidgets since it is another extreme example of error-prone simple bookkeeping (i.e. syncing state between 2 stateful libraries).
Although this PR is quite large, the second commit, or rather, this diff:
is the complete replacement of #273, or rather:
Which is significantly less code and therefore less likely to be buggy (I might have missed a _x or mistyped one).
Using react (for ipywidgets) is not without its own problem, mostly a rather steep learning curve.
I do like the replacement of the LayerArtist by simply 1 function:
I'm not sure it's wise to adopt react-ipywidget in the near term, but I think this PR is useful to have as an example of what this would look like.