electron-pubsub
v0.2.2
Published
Pubsub for electron
Downloads
10
Readme
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.