[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gambas-bugtracker] Bug #3169: Native support for Browser LocalStorage/SessionStorage in gb.web.gui


http://gambaswiki.org/bugtracker/edit?object=BUG.3169&from=L21haW4-

Comment #2 by Omar MORENO:

Hi Benoît,

Yes, exactly! You hit the nail on the head with your second point.

What I am proposing is a Gambas class that mimics the LocalStorage/SessionStorage interface on the server side, automatically handling the JavaScript injection and data synchronization under the hood.

The main reason why doing this manually (injecting JS and using hidden WebTextBox controls) is problematic is synchronization and race conditions.

Since HTTP/WebForms communication is asynchronous, if I need to read a device token from LocalStorage during the Form_Open event to validate a session, I have to:

Inject the JS to read the value.

Dump it into a hidden field.

Wait for the _Change event to actually have the data available in Gambas.

By the time the event fires, the rest of my server-side initialization code has already executed, breaking the logical flow.

What we need:
A native, abstract way to handle this so the developer doesn't have to deal with hidden controls or manual JS injection.

If it's possible to implement it as a synchronous call (blocking the Gambas event execution until the client returns the value), or via a clean callback mechanism, it would be perfect.

For example:

' To save a token on login
WebForm.Storage.Set("device_token", sToken)

' To read it on Form_Open
Dim sToken As String = WebForm.Storage.Get("device_token")

This would keep the simplicity of Gambas while robustly solving client-side state management.

Thank you for analyzing this!



----[ Gambas bugtracker-list is hosted by https://www.hostsharing.net ]----