UNPKG

observable-callback

Version:

A small utility for simplified creation of callback functions that publishes the argument to an observable stream when called.

26 lines (20 loc) 642 B
import {observableCallback} from "./observableCallback" import {concat, Observable, of} from "rxjs" import {map} from "rxjs/operators" // const [keywords$, onInput] = observableCallback( // pipe( // map((data: string) => data.split(" ")), // map((arr) => arr.map((kw) => kw.toUpperCase())) // ) // ) const [keywords$, onInput] = observableCallback((input$: Observable<string>) => concat(of("initial value"), input$).pipe( map((data) => data.split(" ")), map((arr) => arr.map((kw) => kw.toUpperCase())) ) ) keywords$.subscribe(console.log) onInput("foo bar baz") setTimeout(() => { onInput("a b c d e") }, 1000)