0.3.4 • Published 6 years ago

fafgag v0.3.4

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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 (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
UMDES moduleNote
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

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago