fafgag

0.3.4 • Public • Published

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
  • Async Function --> Promise --> Observable
  • Generator --> Iterator --> Observable
  • Async 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 (+ 1) * (+ 1)
}
await function* ag(n) {
  yield n * n
  await sleep(1000)
  yield (+ 1) * (+ 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

Package Sidebar

Install

npm i fafgag

Weekly Downloads

4

Version

0.3.4

License

MIT

Unpacked Size

14.7 kB

Total Files

6

Last publish

Collaborators

  • cognitom