Skip to content

LukeWood/tiny-pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors