Skip to content

Commit

Permalink
Update readme and fix a 'this' bug in _read
Browse files Browse the repository at this point in the history
  • Loading branch information
gtjoseph committed Dec 26, 2015
1 parent 11d7140 commit d966852
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 11 additions & 5 deletions Readme.md
Expand Up @@ -86,12 +86,18 @@ Everything else should work as expected.
## API
See the [API JSDocs](dist/index.html) in the dist directory.

## Promises
## Notes for Node < 4.0.0

MikroNode requires 2 ES6 features that appeared in Node 4.0.0: Promises and WeakMaps. If
you're running an earlier version of Node and MikroNode can't find those symbols, it will
attempt to load them from the 'es6-promise' and 'weakmap' packages respectively. If you wish
to use other packages to supply those symbols, require them before requiring mikronode and
set the global symbols.

global.WeakMap = require('some-weakmap-polyfill').WeakMap;
global.Promise = require('some-promise-polyfill').Promise;
var MikroNode = require('mikronode');

Promises are now supported for Connection and Channel. nodejs versions > 4.0 include
an ES6 Promise implementation. For earlier versions, installing es6-promise and running
require('es6-promise').polyfull() before requiring mikronode will set up Promise support.
You can also globally export Promise from your favorite ES6 compatable Promise library.

## Tests
The [test](test/) directory contains a test that exercises all functionality including
Expand Down
12 changes: 6 additions & 6 deletions lib/connection.js
Expand Up @@ -248,7 +248,7 @@ module.exports = (function() {
_(this).currentChannelId = tagChannelId;

if ((((_(this).currentProgress === '!done' && (_(this).currentReply === '!re'))) || !more)) {
debugSentence('Sentence2: Done channel ' + tagChannelId + '.');
debugSentence('Sentence2: Done channel %s Trapped? %o', tagChannelId, !!_(this).traps[tagChannelId]);
_(this).packet = _(this).buffer; // backup up the packet
_(this).buffer = [];
if (_(this).channel[tagChannelId]) {
Expand All @@ -260,7 +260,7 @@ module.exports = (function() {
debugSentence('Sentence2: caught second trap');
_(this).traps[tagChannelId].addTrapError();
}
debugSentence('Sentence2: caught a trap');
debugSentence('Sentence2: caught a trap for channel %s ', tagChannelId);
var trap = new Trap();
trap.channelId = tagChannelId;
trap.channel = _(this).channel[tagChannelId];
Expand Down Expand Up @@ -299,11 +299,11 @@ module.exports = (function() {
}

} else if (data === '!trap') {
_(this).currentReply = data;
_(this).currentProgress = data;
_(this).buffer[_(this).buffer.length] = data;

} else {
if (_(this).currentReply === '!trap') {
if (_(this).currentProgress === '!trap') {
var m = data.match(/^=(category|message)=(.+)/);
if (m) {
var ct = _(this).traps[_(this).currentChannelId];
Expand All @@ -327,7 +327,7 @@ module.exports = (function() {
* @param {string} data - Sentence
* @this mikronode.Connection
*/
Connection.prototype._read = function read(data) {
Connection.prototype._read = function _read(data) {
if (debugSocketData.enabled) {
utils.hexDump(data, debugSocketData);
}
Expand All @@ -344,7 +344,7 @@ module.exports = (function() {
_(this).line += data.toString();
debugSocketData('read:consume-all: data:' + data);
if (_(this).len === 0) {
this.sentence((this).line, (data.length !== _(this).len));
this.sentence(_(this).line, (data.length !== _(this).len));
_(this).line = '';
}
break;
Expand Down

0 comments on commit d966852

Please sign in to comment.