electron-pubsub

0.2.2 • Public • Published

electron-pubsub

Pubsub for Electron.

You can use it in main or renderer process.

Usage

Initialization

npm install --save electron-pubsub

// in main process
const pubsub = require('electron-pubsub');

// in renderer process
const pubsub = require('electron').remote.require('electron-pubsub');

Subscribe

pubsub.subscribe('myTopic', (event, ...args) => {
    // do something here.
});
 
pubsub.once('anotherTopic', someCallback);

Publish

// in any process
pubsub.publish('myTopic', 'some arguments');

Unsubscribe

// in any process
pubsub.unsubscribe('myTopic', someCallback);
pubsub.unsubscribe('myTopic');
 
pubsub.clearAllSubscriptions();

Hierarchical addressing

pubsub.subscribe('a', myFunc1);
pubsub.subscribe('a.b', myFunc2);
pubsub.subscribe('a.b.c', myFunc3);
 
pubsub.unsubscribe('a.b');

Use promises

pubsub.publish('myTopic', 'some arguments')
    .then(onSuccess)
    .catch(onFailure);
 
pubsub.subscribe('myTopic', (event, ...args) => {
    event.resolve('success!');
});

TODO

  • Support hierarchy of topics.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.22latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.22
0.2.10
0.2.00
0.1.0-alpha.00
0.1.00
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i electron-pubsub

Weekly Downloads

2

Version

0.2.2

License

MIT

Last publish

Collaborators

  • jianfei