Skip to content
No description, website, or topics provided.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
LICENSE
README.md
package.json
pubsub.js

README.md

tiny-pubsub

You probably don't need a framework

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.

You can’t perform that action at this time.