A Dart event emitter implementation without any dependencies.
- dart>=1.20.0
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
}
./scripts/test
git clone https://github.com/axetroy/event-emitter.dart.git
cd ./event-emitter.dart
pub get
./scripts/test
You can flow Contribute Guide
The MIT License