WeakMap and WeakSet aren't iterable, you cannot discover what they contain, 
you have to know and can only check if it's in the map/set and for a map 
get its associated value. This is of no use for an event bus wanting to 
keep weak references to its handlers.

A WeakRef would be the only way, other than implementing explicit 
reference-counting.

On Saturday, August 29, 2020 at 11:21:03 AM UTC+2, Gordan Krešić wrote:
>
> I would like to ask for any advice/idea on how to use event buses in GWT. 
> So 
> far I'm using GWT's own com.google.gwt.event.shared.EventBus, but wouldn't 
> have issues migrating to other implementations. 
>
> My concern goes to very cumbersome and error prone handling when to 
> unregister subscribers to allow them to be garbage collected. I'm aware of 
> ResettableEventBus, but it doesn't solve problems when I don't have clear 
> events to unregister whole classes of subscribers (if I'm not mistaken, it 
> was designed to be used inside single Activity and unregister all 
> subscribers when activity stops, but that flow doesn't work for me, 
> because 
> I need subscribers active even when they are not in current activity). 
>
> When possible, I'm subscribing to events in "onLoad" event and 
> unsubscribing 
> in "onUnload", but that also doesn't work in not-that-uncommon corner 
> cases 
> when I need subscribers active even when detached from DOM. 
>
> Only "solution" that works is manually unregistering when I'm sure 
> subscriber is going away, but as I said, that is very error prone (and 
> beats 
> the purpose of having a garbage collected language). 
>
> WeakReference(s) are not supported. Is there any implementation trying to 
> utilize JS's WeakMap? 
>
> Any other ideas? 
>
>         -gkresic. 
>

-- 
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 google-web-toolkit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/320e677e-41d8-4a89-bd5d-9554bbb8b936o%40googlegroups.com.

Reply via email to