Thanks Jens. Now switched it to use
$doc. And, yes, I just register once, and fire a custom event on the event bus. Although, I just did it using my own event bus like this:
final EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);
listenForVisibilityChange(new Command() {
@Override
public void execute() {
boolean visible = "visible".equals(getVisibilityState());
EVENT_BUS.fireEvent(new WindowVisibilityChangedEvent(visible));
}
});
I suspect your way is better, although, I don't really understand what sinking events onto the DOM is doing.
elemental2 looks cool! Will check it out.
My custom event if anyone wants to reuse it:
public class WindowVisibilityChangedEvent extends GwtEvent<WindowVisibilityChangedEventHandler> {
public static Type<WindowVisibilityChangedEventHandler> TYPE = new Type<WindowVisibilityChangedEventHandler>();
private boolean visibile;
public WindowVisibilityChangedEvent(boolean visible) {
this.visibile = visible;
}
@Override
public Type<WindowVisibilityChangedEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(WindowVisibilityChangedEventHandler handler) {
handler.visibilityChanged(this);
}
public boolean isVisibile() {
return visibile;
}
}
And the handler:
public interface WindowVisibilityChangedEventHandler extends EventHandler {
void visibilityChanged(WindowVisibilityChangedEvent windowVisibilityChangedEvent);
}
Cheers.