@basic-streams/repair
v1.0.0
Published
repair operator for basic-streams
Downloads
281
Readme
@basic-streams/repair
repair<T>(streamLoose: StreamLoose<T>): Stream<T>
Creates a stream from a loose stream that may not follow all the requirements of the protocol. The loose stream is allowed to:
- Return not a function. If the return value is not a function, it will be ignored.
- Pass more than one argument to the callback. The resulting stream will pass only the first argument to its callback.
- Disposer may return value of any type. The resulting stream's disposer
will always return
undefined
. - Call the callback after disposer was called. The resulting stream will ignore these calls.
import repair from "@basic-streams/repair"
const stream = repair(cb => {
// extra arguments will be ignored
cb(1, "extra")
// we don't have to return a function
return null
})
const unsubscribe = stream((...args) => {
console.log(...args)
})
unsubscribe()
// > 1
The type StreamLoose
defined as follows, and you can import it from
@basic-streams/repair
.
type StreamLoose<T> = (cb: (payload: T, ...rest: any[]) => void) => any
import {StreamLoose} from "@basic-streams/repair"