Skip to main content

Creation Operators

from

Converts an array into a sequence of values.

output.svg
import { from } from "@devicescript/observables"

const obs = from([0, 1, 2, 3, 4])

obs.subscribe(v => console.log(v))

interval

Emits a value at a time interval. The value is the number of callbacks. This observable runs forever.

output.svg
import { interval } from "@devicescript/observables"

const obs = interval(1000)

obs.subscribe(v => console.log(v))

timer

Emits a single value, 0 after a time interval, then completes.

output.svg
import { timer } from "@devicescript/observables"

const obs = timer(1000)

obs.subscribe(v => console.log(v))

iif

Checks a boolean at subscription time, and chooses between one of two observable sources.

import { from, iif } from "@devicescript/observables"

let connected: boolean
const obs = iif(() => connected, from(["connected"]), from(["not connected"]))

obs.subscribe(v => console.log(v))