DartEventEmitter.dart

Build Status Coverage Status

Basic implementation of EventEmitter in Dart - a port of Node.js' EventEmitter enhanced with Dart goodness.

Installation

To install package in your system, declare it as a dependency in pubspec.yaml:

dependencies:
    dart_event_emitter: ">=1.0.0 <2.0.0"

Then import dart_event_emitter in your project

import 'dart_event_emitter/dart_event_emitter.dart';

Usage

As an instance

You can treat EventEmitter class as a object holding data about your events:

class MyAwesomeClass {
    EventEmitter _emitter = new EventEmitter();
    
    MyAwesomeClass() {
        _emitter.on('action', () {
            print 'Action recorded!';
        });
    }
    
    void doAwesomeThings() {
        _emitter.emit('action');
    }
}

As a parent class

You can also decide that your class be responsible for own events:

class MyAwesomeClass extends EventEmitter {
    MyAwesomeClass() {
        on('action', () {
            print 'Action recorded!';
        });
    }
    
    void doAwesomeThings() {
        emit('action');
    }
}

To be done

  • asynchronous event handling with Futures
  • register handlers and events with annotations

Libraries

dart_event_emitter

Basic implementation of EventEmitter in Dart - a port of Node.js' EventEmitter enhanced with Dart goodness.