event_dart: ^2.0.0 copied to clipboard
Event_dart is a professional implementation of the NodeJS EventEmitter for Dart.
THIS LIBRARY WAS ORIGINALLY CREATED BY DESIGNTURE.
This project introduces a class to be used as a mixin to allow a class to act as an event emitter to which others can subscribe. Several event-related projects existed, but none of them offered the flexibility and simplicity that we wanted, so we created event_dart.
event_dart is a professional implementation of event_dart for Dart. This is based on the Node.js event_dart enhanced with Dart super power!
To install package in your system, declare it as a dependency in
dependencies: event_dart: ">=1.0.0 <2.0.0"
event_dart in your project
You can use strings to identify the event, and provide additional data separately:
// to emit: emitter.emit('success', result_var); // to subscribe: emitter.on('success', (String r) => doStuff(r));
You can send zero or even to three elements to handler, like that:
emitter.emit('event', arg1, arg2, arg3); // if you need more arguments use the power of lists emitter.emit('event', arg1, arg2, [arg3, arg4, arg5]);
Unsubscribing an event #
removeListener() method allow you to remove a listener for a given event.
This removes normal listeners or even one-time event handlers.
Remove all listeners for an event #
If you want remove all the listeners who are listening a certain event, you use the
Remove all listeners #
You can also unsubscribe all events from an event emitter as follows:
Features and bugs #
Please file feature requests and bugs at the issue tracker.