eps90 / event-emitter.dart

Implementation of node.js EventEmitter in Dart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DartEventEmitter

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 'package: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

About

Implementation of node.js EventEmitter in Dart

License:MIT License


Languages

Language:Dart 99.2%Language:Shell 0.8%