From 9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Thu, 19 Apr 2018 14:37:08 -0400 Subject: Add more documentation to computed balances controller --- app/scripts/lib/port-stream.js | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'app/scripts/lib/port-stream.js') diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js index a9716fb00..260530e63 100644 --- a/app/scripts/lib/port-stream.js +++ b/app/scripts/lib/port-stream.js @@ -6,6 +6,13 @@ module.exports = PortDuplexStream inherits(PortDuplexStream, Duplex) +/** + * Creates a stream that's both readable and writable. + * The stream supports arbitrary JavaScript objects. + * + * @class + * @param {Object} port Remote Port object + */ function PortDuplexStream (port) { Duplex.call(this, { objectMode: true, @@ -15,8 +22,13 @@ function PortDuplexStream (port) { port.onDisconnect.addListener(this._onDisconnect.bind(this)) } -// private - +/** + * Callback triggered when a message is received from + * the remote Port associated with this Stream. + * + * @private + * @param {Object} msg - Payload from the onMessage listener of Port + */ PortDuplexStream.prototype._onMessage = function (msg) { if (Buffer.isBuffer(msg)) { delete msg._isBuffer @@ -27,14 +39,31 @@ PortDuplexStream.prototype._onMessage = function (msg) { } } +/** + * Callback triggered when the remote Port + * associated with this Stream disconnects. + * + * @private + */ PortDuplexStream.prototype._onDisconnect = function () { this.destroy() } -// stream plumbing - +/** + * Explicitly sets read operations to a no-op + */ PortDuplexStream.prototype._read = noop + +/** + * Called internally when data should be written to + * this writable stream. + * + * @private + * @param {*} msg Arbitrary JavaScript object to write + * @param {string} encoding Encoding to use when writing payload + * @param {Function} cb Called when writing is complete or an error occurs + */ PortDuplexStream.prototype._write = function (msg, encoding, cb) { try { if (Buffer.isBuffer(msg)) { -- cgit From 8636f3bae547ace7d099a3ed516bf013dfe3858e Mon Sep 17 00:00:00 2001 From: bitpshr Date: Thu, 19 Apr 2018 15:12:04 -0400 Subject: Clean up JSDoc for background scripts --- app/scripts/lib/port-stream.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/port-stream.js') diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js index 260530e63..5c4224fd9 100644 --- a/app/scripts/lib/port-stream.js +++ b/app/scripts/lib/port-stream.js @@ -8,7 +8,7 @@ inherits(PortDuplexStream, Duplex) /** * Creates a stream that's both readable and writable. - * The stream supports arbitrary JavaScript objects. + * The stream supports arbitrary objects. * * @class * @param {Object} port Remote Port object @@ -60,7 +60,7 @@ PortDuplexStream.prototype._read = noop * this writable stream. * * @private - * @param {*} msg Arbitrary JavaScript object to write + * @param {*} msg Arbitrary object to write * @param {string} encoding Encoding to use when writing payload * @param {Function} cb Called when writing is complete or an error occurs */ -- cgit