Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stevenroose/dart-event-emitter
An event emitter implementation
https://github.com/stevenroose/dart-event-emitter
Last synced: about 1 month ago
JSON representation
An event emitter implementation
- Host: GitHub
- URL: https://github.com/stevenroose/dart-event-emitter
- Owner: stevenroose
- License: mit
- Created: 2014-09-29T19:14:01.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-30T22:23:59.000Z (over 10 years ago)
- Last Synced: 2024-10-30T20:24:16.233Z (3 months ago)
- Language: Dart
- Size: 118 KB
- Stars: 0
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Event Emitter
=============
An event emitter implementation. Good for loose coupling of components.Examples
--------
```dart
import 'package:event_emitter/event_emitter.dart';main() {
var events = new EventEmitter();
var handler = (v) => print("*** called handler");events.emit("boom", "some data");
print("should not have called handler.");events.on("boom", handler);
events.emit("boom", "some data");
print("should have called handler.");events.off("boom", handler);
events.emit("boom", "some data");
print("should not have called handler.");events.on("boom", handler);
events.clearListeners();
events.emit("boom", "some data");
print("should not have called handler.");}
```Public Interface
----------------
```dart
library event_emitter;import 'package:dictionary/dictionary.dart';
class EventEmitter {
/**
* Typical constructor
*/
EventEmitter();/**
* This function triggers all the handlers currently listening
* to `event` and passes them `data`.
*
* @param {String} event - The event to trigger
* @param {dynamic} data - The data to send to each handler
* @return {void}
*/
void emit(String event, dynamic data);/**
* This function binds the `handler` as a listener to the `event`
*
* @param {String} event - The event to add the handler to
* @param {Function} handler - The handler to bind to the event
* @return {void}
*/
void on(String event, Function handler);/**
* This function attempts to unbind the `handler` fromt the `event`
*
* @param {String} event - The event to remove the handler from
* @param {Function} handler - The handler to remove
* @return {void}
*/
void off(String event, Function handler);/**
* This function unbinds all the handlers for all the events
*
* @return {void}
*/
void clearListeners();}
```