Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fafgag

cognitom3MIT0.3.4

Creates an Observable from FAFGAG (Function / Async Function / Generator / Async Generator)

observable, async iteration, async generator

readme

FAFGAG

Travis CI npm

Creates an Observable from FAFGAG (Function / Async Function / Generator / Async Generator)

Installation

$ npm install fafgag

Usage

fafgag converts the results which returned from FAFGAG into Observables:

  • Function --> Value --> Observable
  • A*sync *Function --> Promise --> Observable
  • Generator --> Iterator --> Observable
  • A*sync *Generator --> Async Iterator --> Observable
import toObservable from "fafgag"

function f(n) {
  return n * n
}
async function af(n) {
  await sleep(1000)
  return n * n
}
function* g(n) {
  yield n * n
  yield (n + 1) * (n + 1)
}
await function* ag(n) {
  yield n * n
  await sleep(1000)
  yield (n + 1) * (n + 1)
}

toObservable(f, 5).subscribe(console.log) // output: 25
toObservable(af, 5).subscribe(console.log) // output: (one sec later) 25
toObservable(g, 5).subscribe(console.log) // output: 25 36
toObservable(ag, 5).subscribe(console.log) // output: 26 (one sec later) 36

Note: only when it get subscribed, it will run. This laziness is the basic behavior of Observables.

Native / Zen

If you prefer Babel's polyfill, import fafgag like this:

import toObservable from "fafgag"

If you prefer zen-observable, import fafgag like this:

import toObservable from "fafgag/lib/zen.js" // for ES module environment
import toObservable from "fafgag/zen" // for other environments

| | UMD | ES module | Note | | :-- | :-- | :-- | :-- | | native (babel) | "fafgag" | "fafgag" | standard, but w/o these methods below | | zen-observable | "fafgag/zen" | "fafgag/lib/zen.js" | map(), filter(), flatMap(), etc. |

License

MIT