diff --git a/index.d.ts b/index.d.ts index eb0a31e..2b3852d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -226,8 +226,8 @@ declare module 'flyd/module/switchlatest' { declare module 'flyd/module/takeuntil' { interface takeuntil { - (source: flyd.Stream, end: flyd.Stream): flyd.Stream; - (source: flyd.Stream): (end: flyd.Stream) => flyd.Stream; + (end: flyd.Stream, src: flyd.Stream): flyd.Stream; + (end: flyd.Stream): (src: flyd.Stream) => flyd.Stream; } const _takeuntil: takeuntil; export = _takeuntil; diff --git a/module/takeuntil/README.md b/module/takeuntil/README.md index fb0e293..875e7d8 100644 --- a/module/takeuntil/README.md +++ b/module/takeuntil/README.md @@ -6,12 +6,12 @@ __Graph__ ``` a: {---1---2---3---4} b: {---------x------} -takeUntil(a, b): {---1---2--------} +takeUntil(b, a): {---1---2--------} ``` __Signature__ -`Stream a -> Stream b -> Stream a` +`Stream a -> Stream b -> Stream b` __Usage__ @@ -20,7 +20,7 @@ const takeUntil = require('flyd/module/takeuntil') const source = flyd.stream() const end = flyd.stream() -const result = takeUntil(source, end) +const result = takeUntil(end, source) source(1)(2) result() // 2 diff --git a/module/takeuntil/index.js b/module/takeuntil/index.js index 9f378c6..26fe551 100644 --- a/module/takeuntil/index.js +++ b/module/takeuntil/index.js @@ -1,6 +1,6 @@ var flyd = require('../../lib'); -module.exports = flyd.curryN(2, function(src, term) { +module.exports = flyd.curryN(2, function(term, src) { return flyd.endsOn(flyd.merge(term, src.end), flyd.combine(function(src, self) { self(src()); }, [src])); diff --git a/module/takeuntil/test/index.js b/module/takeuntil/test/index.js index b5be138..5452776 100644 --- a/module/takeuntil/test/index.js +++ b/module/takeuntil/test/index.js @@ -5,24 +5,26 @@ var assert = require('assert'); var takeUntil = require('../index'); describe('takeUntil', function() { - it('emits values from first stream', function() { + it('emits values from source stream', function() { var result = []; var source = stream(); var terminator = stream(); - var s = takeUntil(source, terminator); - flyd.map(function(v) { result.push(v); }, s); + source + .pipe(takeUntil(terminator)) + .map(function(v) { result.push(v); }); source(1)(2)(3); assert.deepEqual(result, [1, 2, 3]); }); - it('ends when value emitted from second stream', function() { + it('ends when value emitted from terminator stream', function() { var result = []; var source = stream(); var terminator = stream(); - var s = takeUntil(source, terminator); - flyd.map(function(v) { result.push(v); }, s); - s(1); + var s = source + .pipe(takeUntil(terminator)) + .map(function(v) { result.push(v); }); + source(1); terminator(true); - s(2); + source(2); assert.deepEqual(result, [1]); assert(s.end()); }); @@ -30,11 +32,12 @@ describe('takeUntil', function() { var result = []; var source = stream(); var terminator = stream(); - var s = takeUntil(source, terminator); - flyd.map(function(v) { result.push(v); }, s); - s(1); + var s = source + .pipe(takeUntil(terminator)) + .map(function(v) { result.push(v); }); + source(1); source.end(true); - s(2); + source(2); assert.deepEqual(result, [1]); assert(s.end()); });