#Eventable Build Status

Eventable provides 2 mixins to make your classes eventable, EventEmitter and EventDetector. Simply use these mixins to make your types either emit, detect or do both for custom events. A custom event can be any object which implements IEvent, Events are emitted asynchronously. Usage is best described with a simple example:

##Example

class Dog extends Object with EventEmitter{

  void bark(int volume){
    emitEvent(
        new BarkEvent()
        ..volume = volume);
  }
  
}

class Cat extends Object with EventDetector{

  void dogBarkHandler(BarkEvent event){
    if(event.volume > 10){
      runaway();
    }else{
      print('cat not disturbed');
    }
  }

  void runaway(){
    print('cat running away');
  }

}

class BarkEvent implements IEvent{
  EventEmitter emitter;
  int volume;
}

void main(){

  var dog = new Dog();
  var cat = new Cat();

  cat.listen(dog, BarkEvent, cat.dogBarkHandler);

  dog.bark(9);  // cat not disturbed
  dog.bark(11); // cat runs away

}

Eventable was designed to allow objects to interact in a loose and non coupled way. The typical usage pattern is to have a model as an EventEmitter and one or more views as EventDetectors of that model, listening to it via its asynchronous events. This way the model operates completely independently of the views and views are easily discarded by calling aView.ignoreAllEvents(); which will fully detach all of the views EventActions, for all event types and EventEmitters.

It is still possible and perfectly legal to use EventEmitters without EventDetectors as they expose their own addEventAction and removeEventAction methods, but this leaves it to the user to handle how to manage removal of the attached EventActions.

##Omni

There is a special event type Omni which is a special value which allows you to listen to every event emitted by an EventEmitter with a single EventAction.

##EventAction

A typedef is specified in the eventable library which serves as the function signature accepted as the last argument to an EventDetectors


typedef void EventAction(Event event);


##DuplicateEventSettingError

A given **EventDetector** can only listen to a specific event type from a specific
**EventEmitter** once, therefore it is an error to try to attach more **EventAction**s
to the same **EventEmitter**/event type combination. If a second attempt is made
by an **EventDetector** to listen to the same **EventEmitter**/event type combination
a **DuplicateEventSettingError** will be thrown.

##EmitTimeQueueChangeError

It is not permitted to add or remove **EventAction**s whilst the event is being
emitted, meaning you may not attach an **EventAction** to an event which adds or
removes **EventAction**s from that same event, if such an attempt is made a 
**EmitTimeQueueChangeError** will be thrown.

Libraries

Eventable

Mixins to make any object into an EventEmitter or EventDetector and create custom Event objects.