You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The next major version of pywebview will introduce state - a way to seamlessly share data between Python and Javascript. State is represented by the pywebview.state object in Javascript and Window.state object in Python. Updating a property on either object will update its value on the other side. An example can be found here.
Additionally, each state object emits an event when state is updated. Implementation details are not set in stone, but currently the syntax is pywebview.state.addEventHandler('change', handler) and window.state += lambda event_type, key, value: pass
State is implemented by means of a proxy in Javascript and an observable class in Python.
The current ahem state can be tracked in the store branch
Ideas, suggestions or questions are welcomed
The text was updated successfully, but these errors were encountered:
As far as I am concerned, basic implementation is done now. Latest changes are pushed into the 6.0 branch.
One limitation of the current version is that it detects changes only on the window.state object itself and mutations of the objects are not registered. Ie this will trigger a state update window.state.counter = 1 and this will not
window.state.nested_counter= {
'counter': 0
}
window.state.nested_counter['counter'] =1# this goes undetected
I have attempted to solve this with two different approaches
By converting dicts and lists to observable versions, which detect and propagate changes. The implementation turned out rather complicated and I could not get it fully working. Besides I am not exactly sure if it is a good approach to convert user data be default
By making State object assignable and introducing sub-states. Something like this
sub_state=State({'counter': 0})
window.state.nested_counter=sub_statesub_state.counter=1# this will be detected
Sub-states have exactly same API as the main state
Anyhow neither of these approaches are implemented, nor will be for the 6.0. It remains to be seen if this feature is needed.
Another feature that might be introduced in the future is global state, a state object which can be shared between different windows.
The next major version of pywebview will introduce state - a way to seamlessly share data between Python and Javascript. State is represented by the
pywebview.state
object in Javascript andWindow.state
object in Python. Updating a property on either object will update its value on the other side. An example can be found here.Additionally, each state object emits an event when state is updated. Implementation details are not set in stone, but currently the syntax is
pywebview.state.addEventHandler('change', handler)
andwindow.state += lambda event_type, key, value: pass
State is implemented by means of a proxy in Javascript and an observable class in Python.
The current ahem state can be tracked in the store branch
Ideas, suggestions or questions are welcomed
The text was updated successfully, but these errors were encountered: