kefir
Version:
Reactive Programming library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory usage
28 lines (21 loc) • 434 B
JavaScript
import {createStream} from '../patterns/one-source'
const mixin = {
_init({fn}) {
this._fn = fn
},
_free() {
this._fn = null
},
_handleValue(x) {
const fn = this._fn
const xs = fn(x)
for (let i = 0; i < xs.length; i++) {
this._emitValue(xs[i])
}
},
}
const S = createStream('flatten', mixin)
const id = x => x
export default function flatten(obs, fn = id) {
return new S(obs, {fn})
}