-
Notifications
You must be signed in to change notification settings - Fork 35
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
Sync view state between Python and JS #112
Comments
FWIW, I think this would be a really useful feature to add to @anywidget/react (as in a new hook or extending the existing hook). |
@kylebarron I see what you're trying to do in #113 - yea, the
@kylebarron do you know if this all works if you comment out the |
Closes #112 In #444 @batpad mentioned > It does seem to make the map a bit slow for me, and we should investigate that, but in principle, this for me works as expected While playing around with that PR, I also saw some view state lagging at low zooms with lots of data rendered. In this screencast I'm smoothly zooming in, but the rendering is very jagged, and sometimes zooms back out slightly. **This screencast is of the previous PR** https://github.com/developmentseed/lonboard/assets/15164633/bbe0a168-b76e-4563-bc30-828d648210db My hypothesis of what's happening is that when rendering lots of data there's a slight lag for deck to call the `onViewStateChange` handler. And so deck will occasionally call the handler with "old" data and that's where you sometimes get the "snap back" in the scrolling. I think this is a really bad UX, and it seems not to happen when deck manages the view state internally. So I think potentially the best UX and performance solution is to decouple the view state from the model, while still syncing from deck to Python in the debounced model handler. This PR tries to implement this. --------- Co-authored-by: Sanjay Bhangar <[email protected]>
Right now we include an
_initial_view_state
that lets Python set the initial view state.deckgl allows you to pass in an
initialViewState
param which then lets deck manage the internal view state. Or you can manage the view state independently from deck, which you update withonViewStateChange
and pass into deck'sviewState
parameter.onViewStateChange
(because we don't want to slow the deck updates)The existing implementation of
useModelState
(in anywidget/react) is:We probably want something like
useModelStateDebounced
which returns a callback that immediately callsmodel.set(key, value)
but debounces formodel.save_changes()
.Note to self: https://www.joshwcomeau.com/snippets/javascript/debounce/ for implementation of debounce + note to use
useMemo
in react. It's unclear if we do wantuseMemo
because we seemingly do want to re-render the react component on every view state change, because deck is reactive and won't re-render the full mapThe text was updated successfully, but these errors were encountered: