-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flip argument order of takeUntil module
The takeUntil module violates one of the first principles of functional programming. Its argument order was (src, end) which is a data first argument order. This commit flips the argument order to (end, src) allowing us to better use takeUntil in pipelines such as: ```js const query = stream(''); // Start fetching the results but if they haven't // arrived when a new query is emitted // stop listening to the stream const results = query .chain(q => fromPromise(getResults(q)) .pipe(takeUntil(query)) ) ``` This also fixes an issue with takeUntil where if the new endStream had a value the dependent stream wouldn't update.
- Loading branch information
Einar Norðfjörð
committed
Jul 12, 2018
1 parent
0b1a435
commit 96c915c
Showing
6 changed files
with
31 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
logs | ||
*.log | ||
|
||
# vscode settings | ||
.vscode | ||
|
||
# Dependency directory | ||
node_modules | ||
bower_components | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
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(stream$, value$)); | ||
}, [s]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
var flyd = require('../../lib'); | ||
var drop = require('ramda/src/drop'); | ||
|
||
module.exports = flyd.curryN(2, function(src, term) { | ||
return flyd.endsOn(flyd.merge(term, src.end), flyd.combine(function(src, self) { | ||
var drop1 = flyd.transduce(drop(1)); | ||
|
||
module.exports = flyd.curryN(2, function(term, src) { | ||
var end$ = flyd.merge(term.hasVal ? drop1(term) : term, src.end); | ||
|
||
return flyd.endsOn(end$, flyd.combine(function(src, self) { | ||
self(src()); | ||
}, [src])); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters