This package has been deprecated

Author message:

The package is renamed to @basic-streams/repair

@basic-streams/from-loose
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

@basic-streams/from-loose

fromLoose<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:

  1. Return not a function. If the return value is not a function, it will be ignored.
  2. Pass more than one argument to the callback. The resulting stream will pass only the first argument to its callback.
  3. Disposer may return value of any type. The resulting stream's disposer will always return undefined.
  4. Call the callback after disposer was called. The resulting stream will ignore these calls.
import fromLoose from "@basic-streams/from-loose"

const stream = fromLoose(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/from-loose.

type StreamLoose<T> = (cb: (payload: T, ...rest: any[]) => void) => any

import {StreamLoose} from "@basic-streams/from-loose"

Package Sidebar

Install

npm i @basic-streams/from-loose

Weekly Downloads

2

Version

0.0.12

License

MIT

Unpacked Size

5.66 kB

Total Files

8

Last publish

Collaborators

  • pozadi