Skip to content

Commit

Permalink
Fix issue with takeUntil in nested stream
Browse files Browse the repository at this point in the history
This issue was caused by #180 which made sure that nested streams were
updated properly. Updating them properly caused nested takeUntil'd
streams to end too soon.
  • Loading branch information
Einar Norðfjörð committed Oct 5, 2018
1 parent 48799a9 commit acce605
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 1 addition & 3 deletions module/switchlatest/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
var flyd = require('../../lib');
var takeUntil = require('../takeuntil');
var drop = require('ramda/src/drop');

var dropCurrentValue = flyd.transduce(drop(1));

module.exports = function(s) {
return flyd.combine(function(stream$, self) {
var value$ = stream$();
flyd.on(self, takeUntil(value$, dropCurrentValue(stream$)));
flyd.on(self, takeUntil(value$, stream$));
}, [s]);
};
6 changes: 5 additions & 1 deletion module/takeuntil/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
var flyd = require('../../lib');
var drop = require('ramda/src/drop');

var dropCurrentValue = flyd.transduce(drop(1));

module.exports = flyd.curryN(2, function(src, term) {
return flyd.endsOn(flyd.merge(term, src.end), flyd.combine(function(src, self) {
var end$ = term.hasVal ? dropCurrentValue(term) : term;
return flyd.endsOn(flyd.merge(end$, src.end), flyd.combine(function(src, self) {
self(src());
}, [src]));
});
20 changes: 20 additions & 0 deletions module/takeuntil/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@ describe('takeUntil', function() {
assert.deepEqual(result, [1]);
assert(s.end());
});

it('works in nested streams', function() {
var source = stream(1);
var terminator = stream(true);

var value = stream(1).chain(function() {
return takeUntil(source, terminator);
})
.map(function(val) {
return val + 1;
});

source(2)(3)(4)(5);

terminator(true);

source(6)(7)(8)(9);

assert.equal(value(), 6);
})
});

0 comments on commit acce605

Please sign in to comment.