Include documentation for module event publishing.

This commit is contained in:
Braydon Fuller 2015-07-29 18:21:09 -04:00
parent 725120a24e
commit ddef234167

View File

@ -106,7 +106,7 @@ the blockchain. One built-in module is the address module which exposes the API
### Writing a Module
A new module can be created by inheriting from `BitcoindJS.Module`, implementing the methods `blockHandler()` and `getAPIMethods()`, and any additional methods for querying the data. Here is an example:
A new module can be created by inheriting from `BitcoindJS.Module`, implementing the methods `blockHandler()`, `getAPIMethods()`, `getPublishEvents()` and any additional methods for querying the data. Here is an example:
```js
var inherits = require('util').inherits;
@ -158,6 +158,31 @@ MyModule.prototype.getAPIMethods = function() {
];
};
/**
* the bus events available for subscription
* @return {Array} array of events
*/
MyModule.prototype.getPublishEvents = function() {
return [
{
name: 'custom',
scope: this,
subscribe: this.subscribeCustom,
unsubscribe: this.unsubscribeCustom
}
]
};
/**
* Will keep track of event listeners to later publish and emit events.
*/
MyModule.prototype.subscribeCustom = function(emitter, param) {
if(!this.subscriptions[param]) {
this.subscriptions[param] = [];
}
this.subscriptions[param].push(emitter);
}
MyModule.prototype.getData = function(arg1, callback) {
// You can query the data by reading from the leveldb store on db
this.db.store.get(arg1, callback);