Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajoslin/busride
Immutable, namespaced event bus
https://github.com/ajoslin/busride
Last synced: 29 days ago
JSON representation
Immutable, namespaced event bus
- Host: GitHub
- URL: https://github.com/ajoslin/busride
- Owner: ajoslin
- License: mit
- Created: 2016-06-08T19:51:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-08T23:01:09.000Z (over 8 years ago)
- Last Synced: 2024-10-18T21:11:41.560Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# busride [![Build Status](https://travis-ci.org/ajoslin/busride.svg?branch=master)](https://travis-ci.org/ajoslin/busride)
> Immutable, namespaced event bus
## Install
```
$ npm install --save busride
```## Usage
```js
var Busride = require('busride')var bus = Busride()
bus.namespace('airplane', {
fly: (payload) => console.log('fly', payload)
})bus.emit('airplane:fly', 'high') // => 'fly high'
```## API
#### `Busride()` -> `bus`
Returns a new event bus.
#### `bus.namespace(name, events)`
##### name
*Required*
Type: `string`The prefix used to call all of the events.
Each namespace can only be declared once.
##### events
*Required*
Type: `objectAn object whose keys are the names of events to expose, and whose values are listeners.
#### `bus.emit(event, payload)`
##### event
*Required*
Type: `string`Must follow the format `namespace:eventName`. It will give sane errors if you give a bad namespace or eventName.
##### payload
*Optional*
Type: `string`One argument, passed into the event's listener.
## License
MIT © [Andrew Joslin](http://ajoslin.com)