callbag-from-obs
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "callbag-from-obs", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Convert an observable to a callbag listenable source", | ||
@@ -20,3 +20,6 @@ "repository": { | ||
"tape": "^4.8.0" | ||
}, | ||
"dependencies": { | ||
"symbol-observable": "^1.2.0" | ||
} | ||
} |
@@ -45,2 +45,4 @@ /** | ||
const $$observable = require('symbol-observable').default; | ||
const fromObs = observable => (start, sink) => { | ||
@@ -55,2 +57,3 @@ if (start !== 0) return; | ||
}); | ||
observable = observable[$$observable] ? observable[$$observable]() : observable; | ||
dispose = observable.subscribe({ | ||
@@ -57,0 +60,0 @@ next: x => sink(1, x), |
52
test.js
const test = require('tape'); | ||
const $$observable = require('symbol-observable').default; | ||
const fromObs = require('./readme'); | ||
@@ -143,1 +144,52 @@ | ||
test('it converts using $$observable', (t) => { | ||
t.plan(13); | ||
const source = fromObs({ | ||
[$$observable]() { | ||
return { | ||
subscribe(observer) { | ||
let i = 0; | ||
let id = setInterval(() => observer.next(i++), 100); | ||
return function unsubscribe() { | ||
clearInterval(id); | ||
}; | ||
} | ||
} | ||
} | ||
}); | ||
const downwardsExpectedTypes = [ | ||
[0, 'function'], | ||
[1, 'number'], | ||
[1, 'number'], | ||
[1, 'number'] | ||
]; | ||
const downwardsExpected = [0, 1, 2]; | ||
let talkback; | ||
source(0, function observe(type, data) { | ||
const et = downwardsExpectedTypes.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) { | ||
talkback = data; | ||
return; | ||
} | ||
if (type === 1) { | ||
const e = downwardsExpected.shift(); | ||
t.deepEquals(data, e, 'downwards data is expected: ' + e); | ||
if (downwardsExpected.length === 0) { | ||
talkback(2); | ||
t.pass('sink disposes the source'); | ||
} | ||
} | ||
}); | ||
setTimeout(() => { | ||
t.pass('nothing else happens after dispose()'); | ||
t.end(); | ||
}, 700); | ||
}); | ||
7919
230
65
1
+ Addedsymbol-observable@^1.2.0
+ Addedsymbol-observable@1.2.0(transitive)