Skip to content

Commit

Permalink
[fix] OCD fixes for test and fixed the by reactor behavior for the re…
Browse files Browse the repository at this point in the history
…combine case
  • Loading branch information
jcrugzz committed Jun 13, 2013
1 parent 34de2c7 commit 04ec58f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions lib/godot/reactor/by.js
Expand Up @@ -31,6 +31,10 @@ var By = module.exports = function (keys, reactor, options) {
this.options = options || {};
this.reactor = reactor;
this.recombine = this.options.recombine || false;
this.sources = this.keys.reduce(function (all, key) {
all[key] = {};
return all;
}, {});
this.streams = this.keys.reduce(function (all, key) {
all[key] = {};
return all;
Expand All @@ -56,15 +60,16 @@ By.prototype.write = function (data) {
var value = data[key];

if (!self.streams[key][value]) {
var source = new FilterStream(key, value);
self.streams[key][value] = self.reactor.createStream(source);
self.pipe(source);
self.sources[key][value] = new FilterStream(key, value);
self.streams[key][value] = self.reactor.createStream(self.sources[key][value]);
if (self.recombine) {
self.streams[key][value].on('data', self.emit.bind(self, 'data'))
self.streams[key][value].on('data', self.emit.bind(self, 'data'));
}
}
self.sources[key][value].write(data);
});
if(!this.recombine) {

if (!this.recombine) {
this.emit('data', data);
}
};
4 changes: 2 additions & 2 deletions test/reactor/by-test.js
Expand Up @@ -61,10 +61,10 @@ vows.describe('godot/reactor/by').addBatch({
),
'by',
12
),
)
}
}).addBatch({
"Should emit pipe the events to the correct pipe-chains": function () {
"Should emit and pipe the events to the correct pipe-chains": function () {
assert.equal(counts.service, 6);
assert.equal(counts['service+ttl'], 12);
assert.equal(counts['service+recombine'], 6);
Expand Down

0 comments on commit 04ec58f

Please sign in to comment.