https://github.com/glorious-codes/glorious-rasket
A simple Pub-Sub implementation
https://github.com/glorious-codes/glorious-rasket
Last synced: about 1 year ago
JSON representation
A simple Pub-Sub implementation
- Host: GitHub
- URL: https://github.com/glorious-codes/glorious-rasket
- Owner: glorious-codes
- License: mit
- Created: 2020-06-12T00:10:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-09T17:32:20.000Z (over 2 years ago)
- Last Synced: 2025-04-19T11:10:07.657Z (about 1 year ago)
- Language: JavaScript
- Size: 2.95 MB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Rasket
> A simple Pub-Sub implementation.
[](https://circleci.com/gh/glorious-codes/glorious-rasket/tree/master)
[](https://coveralls.io/github/glorious-codes/glorious-rasket?branch=master)
## Installation
```
$ npm install -S @glorious/rasket
```
## Usage
### Subscribe
``` javascript
/*
** @eventName: String [required]
** @callback: Function [required]
*/
import rasket from '@glorious/rasket';
const eventName = 'user:updated';
const callback = data => {
// This function will be called every time 'user:updated' is published.
}
const subscriptionId = rasket.subscribe(eventName, callback);
```
### Unsubscribe
``` javascript
/*
** @subscriptionId: String [required]
*/
import rasket from '@glorious/rasket';
const subscriptionId = rasket.subscribe('event:name', data => {});
// When you no longer needs to listen the event,
// you can unsubscribe from it:
rasket.unsubscribe(subscriptionId);
```
### Publish
``` javascript
/*
** @eventName: String [required]
** @data: Any [optional]
*/
import rasket from '@glorious/rasket';
const eventName = 'user:updated';
const data = { name: 'John Duo', email: 'john@gmail.com' };
rasket.publish(eventName, data);
// At this moment, every piece of code subscribed on 'user:updated'
// will be notified with that data.
```
## Contributing
1. Install [Node](https://nodejs.org/en/). Download the "Recommend for Most Users" version.
2. Clone the repo:
``` bash
git clone git@github.com:glorious-codes/glorious-rasket.git
```
3. Go to the project directory:
``` bash
cd glorious-rasket
```
4. Install the project dependencies:
``` bash
npm install
```
## Tests
Ensure that all code that you have added is covered with unit tests:
``` bash
npm run test -- --coverage
```