callbag-flatten
Advanced tools
Comparing version
@@ -27,3 +27,3 @@ 'use strict'; | ||
else if (t === 2 && d) { | ||
outerTalkback(2); | ||
outerTalkback && outerTalkback(2); | ||
sink(2, d); | ||
@@ -30,0 +30,0 @@ } else if (t === 2) { |
@@ -25,3 +25,3 @@ const flatten = source => (start, sink) => { | ||
else if (t === 2 && d) { | ||
outerTalkback(2); | ||
outerTalkback && outerTalkback(2); | ||
sink(2, d); | ||
@@ -28,0 +28,0 @@ } else if (t === 2) { |
{ | ||
"name": "callbag-flatten", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Callbag operator that flattens a higher-order callbag source", | ||
@@ -5,0 +5,0 @@ "repository": { |
49
test.js
@@ -393,3 +393,3 @@ const test = require('tape'); | ||
test('it should not try unsubscribe from completed source when waiting for inner completion', t => { | ||
test('it should not try to unsubscribe from completed source when waiting for inner completion', t => { | ||
t.plan(5); | ||
@@ -435,1 +435,48 @@ | ||
}); | ||
test('it should not try to unsubscribe from completed source when for inner errors', t => { | ||
t.plan(7); | ||
const outerExpectedType = [ | ||
[0, 'function'], | ||
]; | ||
const downwardsExpectedType = [ | ||
[0, 'function'], | ||
[2, 'boolean'], | ||
]; | ||
function sourceOuter(type, data) { | ||
const et = outerExpectedType.shift(); | ||
t.equals(type, et[0], 'outer type is expected: ' + et[0]); | ||
t.equals(typeof data, et[1], 'outer data type is expected: ' + et[1]); | ||
if (type === 0) { | ||
const sink = data; | ||
sink(0, sourceOuter); | ||
sink(1, true); | ||
sink(2); | ||
} | ||
} | ||
function sourceInner(type, data) { | ||
if (type === 0) { | ||
const sink = data; | ||
sink(0, sourceInner); | ||
setTimeout(() => sink(2, true), 0); | ||
} | ||
} | ||
function sink(type, data) { | ||
const et = downwardsExpectedType.shift(); | ||
t.equals(type, et[0], 'downwards type is expected: ' + et[0]); | ||
t.equals(typeof data, et[1], 'downwards data type is expected: ' + et[1]); | ||
}; | ||
const source = flatten(map(() => sourceInner)(sourceOuter)); | ||
source(0, sink); | ||
setTimeout(() => { | ||
t.pass('nothing else happens'); | ||
t.end(); | ||
}, 100); | ||
}); |
17903
7.07%518
8.14%