API Reference 0.3.24dart_web_toolkit_eventResettableEventBus

ResettableEventBus class

Wraps an EventBus to hold on to any HandlerRegistrations, so that they can easily all be cleared at once.

class ResettableEventBus extends EventBus {
 final EventBus _wrapped;
 final Set<HandlerRegistration> _registrations = new Set<HandlerRegistration>();

 ResettableEventBus(this._wrapped);

 
 HandlerRegistration addHandler(EventType type, EventHandler handler) {
   HandlerRegistration rtn = _wrapped.addHandler(type, handler);
   return _doRegisterHandler(rtn);
 }

 
 HandlerRegistration addHandlerToSource(EventType type, Object source, EventHandler handler) {
   HandlerRegistration rtn = _wrapped.addHandlerToSource(type, source, handler);
   return _doRegisterHandler(rtn);
 }

 
 void fireEvent(IEvent event) {
   _wrapped.fireEvent(event);
 }

 
 void fireEventFromSource(IEvent event, Object source) {
   _wrapped.fireEventFromSource(event, source);
 }

 /**
  * Remove all handlers that have been added through this wrapper.
  */
 void removeHandlers() {
   
   while (_registrations.length > 0) {
     HandlerRegistration r = _registrations.first;
     
     /*
      * must remove before we call removeHandler. Might have come from nested
      * ResettableEventBus
      */
     _registrations.remove(r);

     r.removeHandler();
   }
 }

 /**
  *  Visible for testing.
  */
 int getRegistrationSize() {
   return _registrations.length;
 }

 HandlerRegistration _doRegisterHandler(HandlerRegistration registration) {
   _registrations.add(registration);
   return new _ResettableHandlerRegistration(this, registration);
 }

 void _doUnregisterHandler(HandlerRegistration registration) {
   if (_registrations.contains(registration)) {
     registration.removeHandler();
     _registrations.remove(registration);
   }
 }
}

Extends

EventBus > ResettableEventBus

Constructors

new ResettableEventBus(EventBus _wrapped) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
ResettableEventBus(this._wrapped);

Methods

HandlerRegistration addHandler(EventType type, EventHandler handler) #

Adds an unfiltered handler to receive events of this type from all sources.

It is rare to call this method directly. More typically an Event subclass will provide a static <code>register</code> method, or a widget will accept handlers directly.

@param <H> The type of handler @param type the event type associated with this handler @param handler the handler @return the handler registration, can be stored in order to remove the

    handler later
docs inherited from EventBus
HandlerRegistration addHandler(EventType type, EventHandler handler) {
 HandlerRegistration rtn = _wrapped.addHandler(type, handler);
 return _doRegisterHandler(rtn);
}

HandlerRegistration addHandlerToSource(EventType type, Object source, EventHandler handler) #

Adds a handler to receive events of this type from the given source.

It is rare to call this method directly. More typically a Event subclass will provide a static <code>register</code> method, or a widget will accept handlers directly.

@param <H> The type of handler @param type the event type associated with this handler @param source the source associated with this handler @param handler the handler @return the handler registration, can be stored in order to remove the

    handler later
docs inherited from EventBus
HandlerRegistration addHandlerToSource(EventType type, Object source, EventHandler handler) {
 HandlerRegistration rtn = _wrapped.addHandlerToSource(type, source, handler);
 return _doRegisterHandler(rtn);
}

void fireEvent(IEvent event) #

Fires the event from no source. Only unfiltered handlers will receive it.

Any exceptions thrown by handlers will be bundled into a UmbrellaException and then re-thrown after all handlers have completed. An exception thrown by a handler will not prevent other handlers from executing.

@throws UmbrellaException wrapping exceptions thrown by handlers

@param event the event to fire

docs inherited from EventBus
void fireEvent(IEvent event) {
 _wrapped.fireEvent(event);
}

void fireEventFromSource(IEvent event, Object source) #

Fires the given event to the handlers listening to the event's type.

Any exceptions thrown by handlers will be bundled into a UmbrellaException and then re-thrown after all handlers have completed. An exception thrown by a handler will not prevent other handlers from executing.

@throws UmbrellaException wrapping exceptions thrown by handlers

@param event the event to fire

docs inherited from EventBus
void fireEventFromSource(IEvent event, Object source) {
 _wrapped.fireEventFromSource(event, source);
}

int getRegistrationSize() #

Visible for testing.

int getRegistrationSize() {
 return _registrations.length;
}

void removeHandlers() #

Remove all handlers that have been added through this wrapper.

void removeHandlers() {
 
 while (_registrations.length > 0) {
   HandlerRegistration r = _registrations.first;
   
   /*
    * must remove before we call removeHandler. Might have come from nested
    * ResettableEventBus
    */
   _registrations.remove(r);

   r.removeHandler();
 }
}