Skip to content

axetroy/event-emitter.dart

Repository files navigation

event emitter for Dart

Build Status License Dart

A Dart event emitter implementation without any dependencies.

Requirement

  • dart>=1.20.0

Usage

import 'package:ee/ee.dart' show EventEmitter;

void main() {
    EventEmitter event = new EventEmitter();
    
    Function cancelSayHello = event.on('greet', (dynamic name) {
      print('hello ${name}');
    });
    
    Function cancelSayHi = event.on('greet', (dynamic name) {
      print('hi ${name}');
    });
    
    event.emit('greet', 'Axetroy');
    // hello Axetroy
    // hi Axetroy
    
    cancelSayHello();   // remove this listener
    
    event.emit('greet', 'Axetroy');
    // hi Axetroy
    
    event.off('greet');
    
    event.emit('greet', 'Axetroy');   // nothing happen
}

Test

./scripts/test

Contribute

git clone https://github.com/axetroy/event-emitter.dart.git
cd ./event-emitter.dart
pub get
./scripts/test

You can flow Contribute Guide

License

The MIT License

About

A Dart event emitter implementation without any dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published