Last updated:
0 purchases
event listener
EventListener #
NodeJS like Event Listener library for dart!
Usage #
On event #
import 'package:event_listener/event_listener.dart';
void main() {
var eventListener = new EventListener();
eventListener.on('log', (String message) {
print("A log: " + message);
});
eventListener.emit('log', 'from me');
}
copied to clipboard
Once event fires one time #
import 'package:event_listener/event_listener.dart';
void main() {
var eventListener = new EventListener();
//This event created by package called every time when you assign new listener to event
eventListener.on('newListener', (MapEntry<String, Event> deletedEvent) {
print("New event name: " + deletedEvent.key);
print("New event caller: " + deletedEvent.value.caller);
});
/*
New event name: log
new event caller: closure (String message) =>
*/
eventListener.once('log', (String message) {
print("A last log: " + message);
//A last log: from me
});
eventListener.emit('log', 'from me');
}
copied to clipboard
Remove listener #
import 'package:event_listener/event_listener.dart';
void main() {
var eventListener = new EventListener();
//This event created by package called every time when you remove a listener from event
eventListener.on('removeListener', (MapEntry<String, Event> deletedEvent) {
print("Deleted event name: " + deletedEvent.key);
print("Deleted event caller: " + deletedEvent.value.caller);
});
/*
Deleted event name: log
Deleted event caller: closure (String message) =>
*/
var logMe = (message) {
print("A last log: " + message);
}
//A last log: from me
eventListener.once('log', logMe);
eventListener.emit('log', 'from me');
eventListener.removeEventListener('log', logMe);
}
copied to clipboard
Remove all listeners #
import 'package:event_listener/event_listener.dart';
void main() {
var eventListener = new EventListener();
var logMe = (String message) {
print("A last log: " + message);
}
eventListener.once('log', logMe);
eventListener.on('log', logMe);
eventListener.emit('log', 'from me');
eventListener.removeAllListeners('log');
}
copied to clipboard
Contributing #
This package made close as NodeJS's Event Listener module, feel free to modify package as long as it looks familiar to Node package
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.