addEventListener indeed is an option (and I'd say possibly a better
option), but AFAICT you could also have done:
DomGlobal.window.onpopstate = new OnpopstateFn() {
@Override
public onInvoke(Event event) {
// do something
}
});
On Wednesday, December 4, 2024 at 5:23:00 AM UTC+1 [email protected]
wrote:
> I'm finally getting around to replacing these calls with Elemental2.
>
> To replace the JSNI method:
>
> public static native void initialise() /*-{
> $wnd.onpopstate = $entry(function(e) {
> @com.blah.YourClass::yourMethodThatListensForUrlChange()();
> });
> }-*/;
>
> I would have thought it would be:
>
> public static void initialise() {
> DomGlobal.window.onpopstate.onInvoke(event -> {
> // Do something
> });
> }
>
> However, that doesn't compile, as onInvoke takes a @JsFunction, not
> a @FunctionalInterface. So, I have to do something like this:
>
> public static void initialise() {
> DomGlobal.window.addEventListener("popstate", event -> {
> // Do something
> });
> }
>
> Is this correct?
>
> On Friday, 16 October 2020 at 3:40:39 pm UTC+11 Craig Mitchell wrote:
>
>> As Tomas said, not directly with History. It's simple JSNI though:
>>
>> public static native void updateURL(String newUrl) /*-{
>> $wnd.history.pushState(newUrl, "", newUrl);
>> }-*/;
>>
>> public static native void initialise() /*-{
>> $wnd.onpopstate = $entry(function(e) {
>> @com.blah.YourClass::yourMethodThatListensForUrlChange()();
>> });
>> }-*/;
>>
>>
--
You received this message because you are subscribed to the Google Groups "GWT
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/google-web-toolkit/60e98ca7-e63b-4f64-b7f2-b6b875e8b092n%40googlegroups.com.