https://github.com/dnbard/easyevents
Simple publish/subscribe library for JavaScript
https://github.com/dnbard/easyevents
Last synced: about 1 year ago
JSON representation
Simple publish/subscribe library for JavaScript
- Host: GitHub
- URL: https://github.com/dnbard/easyevents
- Owner: dnbard
- Created: 2014-01-16T11:36:47.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-01-17T13:47:01.000Z (over 12 years ago)
- Last Synced: 2025-01-26T05:41:28.536Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 145 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
EasyEvents
==========
EasyEvents is free publish/subscribe library for JavaScript.
Key features
==========
* Dependency free
* All subscriber calls are asynchronous
* Working in any browser or environment that support Javascript
* Easy to use and understand
* Small, less than 1kb minified
Example
==========
```javascript
// create a function to receive messages
var myFunc = function(event, data){
console.log(new Date() + ' Event with name "' + event + '" is triggered');
};
// subscribe function to message with name 'message-name'
// method returns token that can be used to unsubscribe that function
var EVENT_TITLE = 'message-name';
var token = EasyEvents.subscribe(EVENT_TITLE, myFunc);
// publish a message
EasyEvents.publish(EVENT_TITLE);
// or publish a message with some data attached to it
EasyEvents.publish(EVENT_TITLE, {
msg: 'Hello, EasyEvents!'
});
// publish a message synchronously
// use with caution and only if you know why your messages should be sent synchronously
EasyEvents.publishSync(EVENT_TITLE);
// unsubscribe from further messages by token
EasyEvents.remove(token);
// unsubscribe from further messages by event name
// this method will remove all functions for that event
EasyEvents.remove(EVENT_TITLE);
//remove ALL subscriptions
EasyEvents.removeAll();