/*============================================================================*/ /* Private Functions */ /*============================================================================*/ private void listenFor(List <LifecycleEvent.Type> types) { foreach (LifecycleEvent.Type type in types) { dispatcher.AddEventListener(type, (Action <IEvent>)catchEvent); } }
/*============================================================================*/ /* Public Functions */ /*============================================================================*/ public void MapListener(IEventDispatcher dispatcher, Enum type, Delegate listener, Type eventClass = null) { if (eventClass == null) { eventClass = typeof(Event); } List<EventMapConfig> currentListeners = _suspended ? _suspendedListeners : _listeners; EventMapConfig config; int i = currentListeners.Count; while (i-- > 0) { config = currentListeners [i]; if (config.Equals (dispatcher, type, listener, eventClass)) return; } Delegate callback = eventClass == typeof(Event) ? listener : (Action<IEvent>)delegate(IEvent evt){ RouteEventToListener(evt, listener, eventClass); }; config = new EventMapConfig (dispatcher, type, listener, eventClass, callback); currentListeners.Add (config); if (!_suspended) { dispatcher.AddEventListener (type, callback); } }
/*============================================================================*/ /* Public Functions */ /*============================================================================*/ public void MapListener(IEventDispatcher dispatcher, Enum type, Delegate listener, Type eventClass = null) { if (eventClass == null) { eventClass = typeof(Event); } List <EventMapConfig> currentListeners = _suspended ? _suspendedListeners : _listeners; EventMapConfig config; int i = currentListeners.Count; while (i-- > 0) { config = currentListeners [i]; if (config.Equals(dispatcher, type, listener, eventClass)) { return; } } Delegate callback = eventClass == typeof(Event) ? listener : (Action <IEvent>) delegate(IEvent evt){ RouteEventToListener(evt, listener, eventClass); }; config = new EventMapConfig(dispatcher, type, listener, eventClass, callback); currentListeners.Add(config); if (!_suspended) { dispatcher.AddEventListener(type, callback); } }
public void Allows_Communication_From_Parent_To_Child() { parentConnector.OnDefaultChannel() .RelayEvent(SupportEvent.Type.TYPE1); childAConnector.OnDefaultChannel() .ReceiveEvent(SupportEvent.Type.TYPE1); bool wasCalled = false; childADispatcher.AddEventListener(SupportEvent.Type.TYPE1, delegate(IEvent obj) { wasCalled = true; }); parentDispatcher.Dispatch(new SupportEvent(SupportEvent.Type.TYPE1)); Assert.That(wasCalled, Is.True); }
/*============================================================================*/ /* Private Functions */ /*============================================================================*/ private EventRelay CreateRelayFor(params Enum[] types) { subject = new EventRelay(source, destination, new List <Enum>(types)); foreach (Enum type in types) { destination.AddEventListener(type, CatchEvent); } return(subject); }
public void Dispatch_DispatchesEvent_On_The_EventDisaptcher() { bool called = false; eventDispatcher.AddEventListener(SupportEvent.Type.TYPE1, (Action) delegate { called = true; }); instance.Try_dispatch(new SupportEvent(SupportEvent.Type.TYPE1)); Assert.That(called, Is.True); }
public void Allows_Communication_Amongst_Children() { childAConnector.OnDefaultChannel() .RelayEvent(SupportEvent.Type.TYPE1); childBConnector.OnDefaultChannel() .ReceiveEvent(SupportEvent.Type.TYPE1); bool wasCalled = false; childBDispatcher.AddEventListener(SupportEvent.Type.TYPE1, delegate(IEvent evt) { wasCalled = true; }); childADispatcher.Dispatch(new SupportEvent(SupportEvent.Type.TYPE1)); Assert.That(wasCalled, Is.True); }
private void AddListener(Enum type) { _source.AddEventListener(type, _destination.Dispatch); }
public void Activate() { _dispatcher.AddEventListener(_type, (Action <IEvent>)EventHandler); }
/*============================================================================*/ /* Public Functions */ /*============================================================================*/ public virtual void Init() { _logger.Debug("Listening for context existence events on Context {0}", _context); _modularityDispatcher.AddEventListener(ModularContextEvent.Type.CONTEXT_ADD, OnContextAdd); }
public void listener_gets_called_as_action() { int callCount = 0; dispatcher.AddEventListener(Type.A, (Action) delegate { callCount++; }); dispatcher.Dispatch(new BlankEvent(Type.A)); Assert.That(callCount, Is.EqualTo(1)); }
/// <summary> /// Adds the event listener. /// </summary> /// <param name="type">The type.</param> /// <param name="listener">The listener.</param> public void AddEventListener(string type, Action <Event> listener) { m_eventDispatcher.AddEventListener(type, listener); }
/** * The same as calling <code>addEventListener</code> directly on the <code>IEventDispatcher</code>, * but keeps a list of listeners for easy ( usually automatic ) removal. * * @param dispatcher The <code>IEventDispatcher</code> to listen to * @param type The <code>Event</code> type to listen for * @param listener The <code>Event</code> handler * @param eventClass Optional Event class for a stronger mapping. Defaults to <code>flash.events.Event</code>. * @param useCapture * @param priority * @param useWeakReference */ public void MapListener( IEventDispatcher dispatcher, string type, Action<Event> listener, Type eventClass = null ) { if( DispatcherListeningEnabled == false && dispatcher == EventDispatcher ) { throw new ContextError( ContextError.E_EVENTMAP_NOSNOOPING ); } if( eventClass == null ) eventClass = typeof(Event); Parameters parameters; int i = Listeners.Count; while ( i-- > 0 ) { parameters = Listeners[i]; if ( parameters.Dispatcher == dispatcher && parameters.Type == type && parameters.Listener == listener && parameters.EventClass == eventClass) { return; } } Action<Event> callback = delegate( Event e ) { RouteEventToListener( e, listener, eventClass ); }; parameters = new Parameters { Dispatcher = dispatcher, Type = type, Listener = listener, EventClass = eventClass, Callback = callback }; Listeners.Add( parameters ); dispatcher.AddEventListener( type, callback ); }
public void AddEventListener <T> (Enum type, Action <T> listener) { _dispatcher.AddEventListener <T> (type, listener); }
/// <summary> /// Static implementation of <see cref="EventDispatcher.AddEventListener(Type, Action)"/>. /// </summary> /// <param name="type">The type of event.</param> /// <param name="handler">The handler.</param> public static void AddEventListener(Type type, Action handler) { eventDispatcher.AddEventListener(type, handler); }
/// <summary> /// Editor entry /// </summary> /// <param name="handler"></param> /// <returns></returns> public void AddListener(EventHandler handler) { _dispatcher.AddEventListener(_eventType, handler, EventPhase.Target | EventPhase.Bubbling); // could not be used for capture phase }
/// <summary> /// 注册事件 /// </summary> /// <typeparam name="TEvent">事件类型</typeparam> /// <param name="handler">处理者</param> /// <param name="priority">优先级</param> public static void AddEventListener <TEvent>(Action <TEvent> handler, int priority = 0) where TEvent : Event { eventDispatcher.AddEventListener <TEvent>(handler, priority); }