public static void UnsubscribeAll(IMediatorListener obj) { foreach (var listener in Listeners.Values) { listener.RemoveAll(x => !x.IsAlive || x.Target == null || x.Target == obj); } }
public static void Unsubscribe(string message, IMediatorListener obj) { if (!Listeners.ContainsKey(message)) { return; } var l = Listeners[message]; l.RemoveAll(x => !x.IsAlive || x.Target == null || x.Target == obj); }
//It is faster to use ForEach do to event uses a nullCe /// <summary> /// Adds a objects that wants to listen to called events /// </summary> /// <param name="listener"></param> public static void AddListener(IMediatorListener listener) { if (listeners.Contains(listener)) { return; } listeners.Add(listener); AddListener(listener.OnMediatorMessageReceived); }
public static void Subscribe(Enum message, IMediatorListener obj) { Listeners.AddValue(message.ToString(), new WeakReference(obj)); }
public static void Unsubscribe(string message, IMediatorListener obj) { if (!Listeners.ContainsKey(message)) return; var l = Listeners[message]; l.RemoveAll(x => !x.IsAlive || x.Target == null || x.Target == obj); }
/// <summary> /// Removes a object that listened to called events /// </summary> /// <param name="listener"></param> public static void RemoveListener(IMediatorListener listener) { listeners.Remove(listener); RemoveListener(listener.OnMediatorMessageReceived); }