Basic implementation of EventEmitter in Dart - a port of Node.js' EventEmitter enhanced with Dart goodness.
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';
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');
}
}
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');
}
}
- asynchronous event handling with Futures
- register handlers and events with annotations