callbag-flatten
Advanced tools
Comparing version
@@ -12,3 +12,3 @@ 'use strict'; | ||
innerTalkback && innerTalkback(2); | ||
outerTalkback(2); | ||
if (!outerEnded) outerTalkback(2); | ||
} | ||
@@ -15,0 +15,0 @@ } |
@@ -10,3 +10,3 @@ const flatten = source => (start, sink) => { | ||
innerTalkback && innerTalkback(2); | ||
outerTalkback(2); | ||
if (!outerEnded) outerTalkback(2); | ||
} | ||
@@ -13,0 +13,0 @@ } |
{ | ||
"name": "callbag-flatten", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Callbag operator that flattens a higher-order callbag source", | ||
@@ -25,2 +25,3 @@ "repository": { | ||
"callbag-map": "1.0.0", | ||
"callbag-never": "^1.0.0", | ||
"rollup": "^0.63.4", | ||
@@ -27,0 +28,0 @@ "tape": "^4.8.0" |
43
test.js
const test = require('tape'); | ||
const map = require('callbag-map'); | ||
const never = require('callbag-never'); | ||
const flatten = require('.'); | ||
@@ -391,1 +392,43 @@ | ||
}); | ||
test('it should not try unsubscribe from completed source when waiting for inner completion', t => { | ||
t.plan(5); | ||
const outerExpectedType = [ | ||
[0, 'function'], | ||
]; | ||
const downwardsExpectedType = [ | ||
[0, 'function'], | ||
]; | ||
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 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]); | ||
if (type === 0) { | ||
const talkback = data; | ||
setTimeout(() => talkback(2), 0); | ||
} | ||
}; | ||
const source = flatten(map(() => never)(sourceOuter)); | ||
source(0, sink); | ||
setTimeout(() => { | ||
t.pass('nothing else happens'); | ||
t.end(); | ||
}, 100); | ||
}); |
16755
12.77%9
12.5%481
8.09%4
33.33%