Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

tiny-pubsub

tiny-pubsub is a super simple event management package written in javascript with no dependencies.

Right now tiny-pubsub is 827 bytes.

This is in no way mean't to replace rxjs. This is a small, synchronously operating, feature-light event driven programming library. RxJs is a full featured event driven programming library.

Installation

npm install --save tiny-pubsub

Usage

The api only has three functions. publish, subscribe, and unsubscribe.

event_definitions.js

// Using object singletons is a good way to register events.
const CHATROOM_JOIN = {};
export {CHATROOM_JOIN}

app.js

import {subscribe, publish, unsubscribe} from 'tiny-pubsub'
import {CHATROOM_JOIN} from './event_definitions'
let logJoin = (name) => console.log(`${name} has joined the room!`);
subscribe(CHATROOM_JOIN, logJoin)
publish(CHATROOM_JOIN, "Luke")
// > Luke has joined the room!
unsubscribe(CHATROOM_JOIN, logJoin)
publish(CHATROOM_JOIN, "Luke")
// nothing will print

// alternatively you can use strings as event identifiers
subscribe("chatroom-join", logJoin)
publish("chatroom-join", "Luke")
// > Luke has joined the room!

Contributing

Send pull requests.

Testing

npm install --dev
npm run test

License

MIT License.

About

No description, website, or topics provided.

Resources

License

Releases

No releases published

Packages

No packages published