Skip to content

harryhope/messenger.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

messenger.js

A simple publish/subscribe implementation for node and the browser.

Installation

npm i @harryhope/messenger

Usage

import messenger from '@harryhope/messenger'

messenger.on('myEvent', name =>
  console.log(`Hello there, ${name}`)
)

messenger.send('myEvent', 'Elvis')

API

messenger.on

Subscribe to an event/topic with a callback function.

const myCallback = str => console.log(`Hello ${str}`)
messenger.on('hello', myCallback)

messenger.off

Unsubscribe to an event.

messenger.off('hello', myCallback)

messenger.send

Broadcast a message to all subscribers of an event.

messenger.send('hello', 'world')
// Displays 'Hello world' in the console.

Development

To build the src just run npm run build.

Tests can be run with npm test.

About

A simple publish/subscribe implementation for node and the browser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published