Options
All
  • Public
  • Public/Protected
  • All
Menu

baconjs

Index

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

Accumulator

Accumulator<In, Out>: (acc: Out, value: In) => Out

Type parameters

  • In

  • Out

Type declaration

    • (acc: Out, value: In): Out
    • Parameters

      • acc: Out
      • value: In

      Returns Out

Afters

Afters: [Observable, Call]

AnyValue

AnyValue: Value<any>

ArrayTemplate

ArrayTemplate<A>: Array

Type parameters

  • A

Binder

Binder<V>: (sink: FlexibleSink<V>) => Unsub

Binder function used in fromBinder

Type parameters

  • V

    Type of stream elements

Type declaration

BoolTuple

BoolTuple<T>: [T, boolean]

Type parameters

  • T

BufferHandler

BufferHandler<V>: (buffer: Buffer<V>) => any

Type parameters

  • V

Type declaration

    • Parameters

      Returns any

Call

Call: () => any

Type declaration

    • (): any
    • Returns any

Combinator

Combinator<V, V2, R>: (x: V, y: V2) => R

Type parameters

  • V

  • V2

  • R

Type declaration

    • (x: V, y: V2): R
    • Parameters

      • x: V
      • y: V2

      Returns R

CombinedTemplate

CombinedTemplate<O>:

Type parameters

  • O

Ctx

Ctx: any

Combines Properties, EventStreams and constant values using a template object. For instance, assuming you've got streams or properties named password, username, firstname and lastname, you can do

var password, username, firstname, lastname; // <- properties or streams
var loginInfo = Bacon.combineTemplate({
magicNumber: 3,
userid: username,
passwd: password,
name: { first: firstname, last: lastname }})

.. and your new loginInfo property will combine values from all these streams using that template, whenever any of the streams/properties get a new value. For instance, it could yield a value such as

{ magicNumber: 3,
userid: "juha",
passwd: "easy",
name : { first: "juha", last: "paananen" }}

In addition to combining data from streams, you can include constant values in your templates.

Note that all Bacon.combine* methods produce a Property instead of an EventStream. If you need the result as an EventStream you might want to use property.changes()

Bacon.combineWith(function(v1,v2) { .. }, stream1, stream2).changes()

DecodedValueOf

DecodedValueOf<O>: FlattenedObservable<O[keyof O]>

Type parameters

  • O

DelayFunction

DelayFunction: (f: VoidFunction) => any

Delay function used by bufferWithTime and bufferWithTimeOrCount. Your implementation should call the given void function to cause a buffer flush.

Type declaration

Differ

Differ<V, V2>: Function2<V, V, V2>

Type parameters

  • V

  • V2

Equals

Equals<A>: (left: A, right: A) => boolean

Type parameters

  • A

Type declaration

    • (left: A, right: A): boolean
    • Parameters

      • left: A
      • right: A

      Returns boolean

EventLike

EventLike<V>: V | Event<V> | Event<V>[]

Type parameters

  • V

EventOrValue

EventOrValue<V>: Event<V> | V

Type parameters

  • V

EventSink

EventSink<V, V>: Sink<Event<V>>

Type parameters

  • V

  • V

EventSourceFn

EventSourceFn: (binder: Function, listener: Function) => any

Type declaration

    • (binder: Function, listener: Function): any
    • Parameters

      • binder: Function
      • listener: Function

      Returns any

EventSpawner

EventSpawner<V, V2>: (e: Event<V>) => Observable<V2> | EventOrValue<V2>

Type parameters

  • V

  • V2

Type declaration

EventTransformer

EventTransformer<V>: (...args: any[]) => EventLike<V>

Type parameters

  • V

Type declaration

FlattenedObservable

FlattenedObservable<O>: O extends Observable<infer I> ? I : O

Type parameters

  • O

FlexibleSink

FlexibleSink<V>: (event: EventLike<V>) => Reply

Type parameters

  • V

Type declaration

Function0

Function0<R>: () => R

Type parameters

  • R

Type declaration

    • (): R
    • Returns R

Function1

Function1<T1, R>: (t1: T1) => R

Type parameters

  • T1

  • R

Type declaration

    • (t1: T1): R
    • Parameters

      • t1: T1

      Returns R

Function2

Function2<T1, T2, R>: (t1: T1, t2: T2) => R

Type parameters

  • T1

  • T2

  • R

Type declaration

    • (t1: T1, t2: T2): R
    • Parameters

      • t1: T1
      • t2: T2

      Returns R

Function3

Function3<T1, T2, T3, R>: (t1: T1, t2: T2, t3: T3) => R

Type parameters

  • T1

  • T2

  • T3

  • R

Type declaration

    • (t1: T1, t2: T2, t3: T3): R
    • Parameters

      • t1: T1
      • t2: T2
      • t3: T3

      Returns R

Function4

Function4<T1, T2, T3, T4, R>: (t1: T1, t2: T2, t3: T3, t4: T4) => R

Type parameters

  • T1

  • T2

  • T3

  • T4

  • R

Type declaration

    • (t1: T1, t2: T2, t3: T3, t4: T4): R
    • Parameters

      • t1: T1
      • t2: T2
      • t3: T3
      • t4: T4

      Returns R

Function5

Function5<T1, T2, T3, T4, T5, R>: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R

Type parameters

  • T1

  • T2

  • T3

  • T4

  • T5

  • R

Type declaration

    • (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R
    • Parameters

      • t1: T1
      • t2: T2
      • t3: T3
      • t4: T4
      • t5: T5

      Returns R

Function6

Function6<T1, T2, T3, T4, T5, T6, R>: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6) => R

Type parameters

  • T1

  • T2

  • T3

  • T4

  • T5

  • T6

  • R

Type declaration

    • (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): R
    • Parameters

      • t1: T1
      • t2: T2
      • t3: T3
      • t4: T4
      • t5: T5
      • t6: T6

      Returns R

GroupTransformer

GroupTransformer<V, V2>: (data: EventStream<V>, firstValue: V) => Observable<V2>

Type parameters

  • V

  • V2

Type declaration

    • (data: EventStream<V>, firstValue: V): Observable<V2>
    • Parameters

      Returns Observable<V2>

ObjectTemplate

ObjectTemplate<O>: {}

Type parameters

  • O

Type declaration

ObservableOrSource

ObservableOrSource<V>: Observable<V> | Source<any, V>

Type parameters

  • V

Pattern

Pattern<O>: Pattern1<any, O> | Pattern2<any, any, O> | Pattern3<any, any, any, O> | Pattern4<any, any, any, any, O> | Pattern5<any, any, any, any, any, O> | Pattern6<any, any, any, any, any, any, O> | RawPattern

Join pattern type, allowing up to 6 sources per pattern.

Type parameters

  • O

Pattern1

Pattern1<I1, O>: [ObservableOrSource<I1>, O | ((a: I1) => O)]

Join pattern consisting of a single EventStream and a mapping function.

Type parameters

  • I1

  • O

Pattern2

Pattern2<I1, I2, O>: [ObservableOrSource<I1>, ObservableOrSource<I1>, O | ((a: I1, b: I2) => O)]

Join pattern consisting of a 2 Observables and a combinator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • O

Pattern3

Pattern3<I1, I2, I3, O>: [ObservableOrSource<I1>, ObservableOrSource<I1>, ObservableOrSource<I3>, O | ((a: I1, b: I2, c: I3) => O)]

Join pattern consisting of a 3 Observables and a combinator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • O

Pattern4

Pattern4<I1, I2, I3, I4, O>: [ObservableOrSource<I1>, ObservableOrSource<I1>, ObservableOrSource<I3>, ObservableOrSource<I4>, O | ((a: I1, b: I2, c: I3, d: I4) => O)]

Join pattern consisting of a 4 Observables and a combinator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • I4

  • O

Pattern5

Pattern5<I1, I2, I3, I4, I5, O>: [ObservableOrSource<I1>, ObservableOrSource<I1>, ObservableOrSource<I3>, ObservableOrSource<I4>, ObservableOrSource<I5>, O | ((a: I1, b: I2, c: I3, d: I4, e: I5) => O)]

Join pattern consisting of a 5 Observables and a combinator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • I4

  • I5

  • O

Pattern6

Pattern6<I1, I2, I3, I4, I5, I6, O>: [ObservableOrSource<I1>, ObservableOrSource<I1>, ObservableOrSource<I3>, ObservableOrSource<I4>, ObservableOrSource<I5>, ObservableOrSource<I6>, O | ((a: I1, b: I2, c: I3, d: I4, e: I5, f: I6) => O)]

Join pattern consisting of a 6 Observables and a combinator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • I4

  • I5

  • I6

  • O

PollFunction

PollFunction<V>: () => EventLike<V>

A polled function used by fromPoll

Type parameters

  • V

Type declaration

Predicate

Predicate<V>: Function1<V, boolean>

Type parameters

  • V

Predicate2Transformer

Predicate2Transformer<V>: (p: Predicate<V>) => Transformer<V, V>

Type parameters

  • V

Type declaration

PredicateOrProperty

PredicateOrProperty<V>: Predicate<V> | boolean | Property<boolean>

Type parameters

  • V

Reply

Reply: "<no-more>" | any

Return type for various Sink functions. Indicates whether or not the sink desires more input from its source. See Bacon.fromBinder for example.

Sink

Sink<V, V>: (value: V) => any

Type parameters

  • V

  • V

Type declaration

    • (value: V): any
    • Parameters

      • value: V

      Returns any

SpawnerOrObservable

SpawnerOrObservable<V, V2>: ValueSpawner<V, V2> | Observable<V2>

Type parameters

  • V

  • V2

Spy

Spy: (obs: Observable<any>) => any

Type declaration

    • (obs: Observable<any>): any
    • Parameters

      • obs: Observable<any>

      Returns any

Subscribe

Subscribe<T>: (arg: EventSink<T>) => Unsub

Type parameters

  • T

Type declaration

Subscription

Subscription<V, V>: (unsubAll: Unsub, unsubMe: Unsub) => Unsub

Type parameters

  • V

  • V

Type declaration

input

input: Observable<V>

sink

sink: EventSink<V>

unsub

unsub: Unsub | undefined

Transformer

Transformer<V1, V2>: (event: Event<V1>, sink: EventSink<V2>) => Reply

Type parameters

  • V1

  • V2

Type declaration

Unsub

Unsub: () => void

an "unsubscribe" function returned by subscribe et al. You can cancel your subscription by calling this function.

Type declaration

    • (): void
    • Returns void

UpdatePattern

UpdatePattern<O>: UpdatePattern1<any, O> | UpdatePattern2<any, any, O> | UpdatePattern3<any, any, any, O> | UpdatePattern4<any, any, any, any, O> | UpdatePattern5<any, any, any, any, any, O> | UpdatePattern6<any, any, any, any, any, any, O>

Update pattern type, allowing up to 6 sources per pattern.

Type parameters

  • O

UpdatePattern1

UpdatePattern1<I1, O>: [Observable<I1>, O | ((acc: O, a: I1) => O)]

Update pattern consisting of a single EventStream and a accumulator function.

Type parameters

  • I1

  • O

UpdatePattern2

UpdatePattern2<I1, I2, O>: [Observable<I1>, Observable<I1>, O | ((acc: O, a: I1, b: I2) => O)]

Update pattern consisting of 2 Observables and an accumulrator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • O

UpdatePattern3

UpdatePattern3<I1, I2, I3, O>: [Observable<I1>, Observable<I1>, Observable<I3>, O | ((acc: O, a: I1, b: I2, c: I3) => O)]

Update pattern consisting of 3 Observables and an accumulrator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • O

UpdatePattern4

UpdatePattern4<I1, I2, I3, I4, O>: [Observable<I1>, Observable<I1>, Observable<I3>, Observable<I4>, O | ((acc: O, a: I1, b: I2, c: I3, d: I4) => O)]

Update pattern consisting of 4 Observables and an accumulrator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • I4

  • O

UpdatePattern5

UpdatePattern5<I1, I2, I3, I4, I5, O>: [Observable<I1>, Observable<I1>, Observable<I3>, Observable<I4>, Observable<I5>, O | ((acc: O, a: I1, b: I2, c: I3, d: I4, e: I5) => O)]

Update pattern consisting of 5 Observables and an accumulrator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • I4

  • I5

  • O

UpdatePattern6

UpdatePattern6<I1, I2, I3, I4, I5, I6, O>: [Observable<I1>, Observable<I1>, Observable<I3>, Observable<I4>, Observable<I5>, Observable<I6>, O | ((acc: O, a: I1, b: I2, c: I3, d: I4, e: I5, f: I6) => O)]

Update pattern consisting of 6 Observables and an accumulrator function. At least one of the Observables must be an EventStream.

Type parameters

  • I1

  • I2

  • I3

  • I4

  • I5

  • I6

  • O

ValueSpawner

ValueSpawner<V, V2>: (value: V) => V2 | Observable<V2> | Event<V2>

Type parameters

  • V

  • V2

Type declaration

    • (value: V): V2 | Observable<V2> | Event<V2>
    • Parameters

      • value: V

      Returns V2 | Observable<V2> | Event<V2>

VoidFunction

VoidFunction: () => void

Type declaration

    • (): void
    • Returns void

VoidSink

VoidSink: () => Reply

Type declaration

Variables

Promise

Promise: any

aftersStack

aftersStack: [Afters[], number][] = []

aftersStackHeight

aftersStackHeight: number = 0

Const combine

combine: combineWith = combineWith

flushed

flushed: {}

Type declaration

  • [key: number]: boolean

idCounter

idCounter: number = 0

Const makeFunction_

makeFunction_: (Anonymous function) = withMethodCallSupport(function(f: Function, ...args: any[]) {if (_.isFunction(f) ) {if (args.length) { return partiallyApplied(f, args); } else { return f; }} else {return _.always(f);}})

Const more

more: Reply = undefined

Reply for "more data, please".

Const noMore

noMore: Reply = "<no-more>"

Reply for "no more data, please".

Const nullMarker

nullMarker: {}

Type declaration

processingAfters

processingAfters: boolean = false

recursionDepth

recursionDepth: number = 0

rootEvent

rootEvent: Event<any> | undefined = undefined

running

running: boolean = false

spies

spies: Spy[] = []

Const version

version: "__version__" = "__version__"

Bacon.js version as string

waiterObs

waiterObs: Observable[] = []

waiters

waiters: {}

Type declaration

  • [obsId: number]: Call[]

Functions

afterTransaction

cannotSync

  • cannotSync(source: AnySource): boolean
  • Parameters

    • source: AnySource

    Returns boolean

combineAsArray

  • combineAsArray<V>(...streams: (Observable<V> | Observable<V>[])[]): Property<V[]>
  • Combines Properties, EventStreams and constant values so that the result Property will have an array of the latest values from all sources as its value. The inputs may contain both Properties and EventStreams.

    property = Bacon.constant(1)
    stream = Bacon.once(2)
    constant = 3
    Bacon.combineAsArray(property, stream, constant)
    # produces the value [1,2,3]

    Type parameters

    • V

    Parameters

    • Rest ...streams: (Observable<V> | Observable<V>[])[]

      streams and properties to combine

    Returns Property<V[]>

combineTemplate

combineWith

  • combineWith<R>(fn: Function0<R>): Property<R>
  • combineWith<V, R>(a: Observable<V>, fn: Function1<V, R>): Property<R>
  • combineWith<V, V2, R>(a: Observable<V>, b: Observable<V2>, fn: Function2<V, V2, R>): Property<R>
  • combineWith<V, V2, V3, R>(a: Observable<V>, b: Observable<V2>, c: Observable<V3>, fn: Function3<V, V2, V3, R>): Property<R>
  • combineWith<V, V2, V3, V4, R>(a: Observable<V>, b: Observable<V2>, c: Observable<V3>, d: Observable<V4>, fn: Function4<V, V2, V3, V4, R>): Property<R>
  • combineWith<V, V2, V3, V4, V5, R>(a: Observable<V>, b: Observable<V2>, c: Observable<V3>, d: Observable<V4>, e: Observable<V5>, fn: Function5<V, V2, V3, V4, V5, R>): Property<R>
  • combineWith<V, V2, V3, V4, V5, V6, R>(a: Observable<V>, b: Observable<V2>, c: Observable<V3>, d: Observable<V4>, e: Observable<V5>, f: Observable<V6>, fn: Function6<V, V2, V3, V4, V5, V6, R>): Property<R>
  • combineWith<R>(observables: Observable<any>[], fn: Function): Property<R>
  • combineWith<V, R>(fn: Function1<V, R>, a: Observable<V>): Property<R>
  • combineWith<V, V2, R>(fn: Function2<V, V2, R>, a: Observable<V>, b: Observable<V2>): Property<R>
  • combineWith<V, V2, V3, R>(fn: Function3<V, V2, V3, R>, a: Observable<V>, b: Observable<V2>, c: Observable<V3>): Property<R>
  • combineWith<V, V2, V3, V4, R>(fn: Function4<V, V2, V3, V4, R>, a: Observable<V>, b: Observable<V2>, c: Observable<V3>, d: Observable<V4>): Property<R>
  • combineWith<V, V2, V3, V4, V5, R>(fn: Function5<V, V2, V3, V4, V5, R>, a: Observable<V>, b: Observable<V2>, c: Observable<V3>, d: Observable<V4>, e: Observable<V5>): Property<R>
  • combineWith<V, V2, V3, V4, V5, V6, R>(fn: Function6<V, V2, V3, V4, V5, V6, R>, a: Observable<V>, b: Observable<V2>, c: Observable<V3>, d: Observable<V4>, e: Observable<V5>, f: Observable<V6>): Property<R>
  • combineWith<R>(fn: Function, observables: Observable<any>[]): Property<R>
  • Combines given n Properties and EventStreams using the given n-ary function f(v1, v2 ...).

    To calculate the current sum of three numeric Properties, you can do

    function sum3(x,y,z) { return x + y + z }
    Bacon.combineWith(sum3, p1, p2, p3)

    Type parameters

    • R

    Parameters

    Returns Property<R>

  • Type parameters

    • V

    • R

    Parameters

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • R

    Parameters

    • a: Observable<V>
    • b: Observable<V2>
    • fn: Function2<V, V2, R>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • R

    Parameters

    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>
    • fn: Function3<V, V2, V3, R>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • V4

    • R

    Parameters

    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>
    • d: Observable<V4>
    • fn: Function4<V, V2, V3, V4, R>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • V4

    • V5

    • R

    Parameters

    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>
    • d: Observable<V4>
    • e: Observable<V5>
    • fn: Function5<V, V2, V3, V4, V5, R>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • V4

    • V5

    • V6

    • R

    Parameters

    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>
    • d: Observable<V4>
    • e: Observable<V5>
    • f: Observable<V6>
    • fn: Function6<V, V2, V3, V4, V5, V6, R>

    Returns Property<R>

  • Type parameters

    • R

    Parameters

    • observables: Observable<any>[]
    • fn: Function

    Returns Property<R>

  • Type parameters

    • V

    • R

    Parameters

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • R

    Parameters

    • fn: Function2<V, V2, R>
    • a: Observable<V>
    • b: Observable<V2>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • R

    Parameters

    • fn: Function3<V, V2, V3, R>
    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • V4

    • R

    Parameters

    • fn: Function4<V, V2, V3, V4, R>
    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>
    • d: Observable<V4>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • V4

    • V5

    • R

    Parameters

    • fn: Function5<V, V2, V3, V4, V5, R>
    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>
    • d: Observable<V4>
    • e: Observable<V5>

    Returns Property<R>

  • Type parameters

    • V

    • V2

    • V3

    • V4

    • V5

    • V6

    • R

    Parameters

    • fn: Function6<V, V2, V3, V4, V5, V6, R>
    • a: Observable<V>
    • b: Observable<V2>
    • c: Observable<V3>
    • d: Observable<V4>
    • e: Observable<V5>
    • f: Observable<V6>

    Returns Property<R>

  • Type parameters

    • R

    Parameters

    • fn: Function
    • observables: Observable<any>[]

    Returns Property<R>

concatAll

  • concatAll<V>(...streams_: (Observable<V> | Observable<V>[])[]): EventStream<V>
  • Concatenates given array of EventStreams or Properties. Works by subscribing to the first source, and listeing to that until it ends. Then repeatedly subscribes to the next source, until all sources have ended.

    See concat

    Type parameters

    • V

    Parameters

    • Rest ...streams_: (Observable<V> | Observable<V>[])[]

    Returns EventStream<V>

constant

  • Creates a constant property with value x.

    Type parameters

    • V

    Parameters

    • x: V

    Returns Property<V>

containsDuplicateDeps

  • containsDuplicateDeps(observables: AnyObservable[], state?: AnyObservable[]): boolean
  • Parameters

    • observables: AnyObservable[]
    • Default value state: AnyObservable[] = []

    Returns boolean

containsObs

currentEventId

  • currentEventId(): undefined | number

ensureStackHeight

  • ensureStackHeight(h: number): void

extractLegacyPatterns

  • extractLegacyPatterns(sourceArgs: any[]): RawPattern[]
  • Parameters

    • sourceArgs: any[]

    Returns RawPattern[]

findHandlerMethods

  • findHandlerMethods(target: any): [Function, Function]
  • Parameters

    • target: any

    Returns [Function, Function]

flush

  • flush(): void

flushDepsOf

flushWaiters

  • flushWaiters(index: number, deps: boolean): void

fromArray

  • Creates an EventStream that delivers the given series of values (given as array) to the first subscriber. The stream ends after these values have been delivered. You can also send Bacon.Error events, or any combination of pure values and error events like this: `Bacon.fromArray([1, new Bacon.Error()])

    typeparam

    Type of stream elements

    Type parameters

    • T

    Parameters

    • values: (T | Event<T>)[]

      Array of values or events to repeat

    Returns EventStream<T>

fromBinder

  • If none of the other factory methods above apply, you may of course roll your own EventStream by using fromBinder.

    Bacon.fromBinder(subscribe) The parameter subscribe is a function that accepts a sink which is a function that your subscribe function can "push" events to.

    For example:

    var stream = Bacon.fromBinder(function(sink) {
    sink("first value")
    sink([new Bacon.Next("2nd"), new Bacon.Next("3rd")])
    sink(new Bacon.Error("oops, an error"))
    sink(new Bacon.End())
    return function() {
    // unsub functionality here, this one's a no-op
    }
    })
    stream.log()

    As shown in the example, you can push

    • A plain value, like "first value"
    • An Event object including Bacon.Error (wraps an error) and Bacon.End (indicates stream end).
    • An array of event objects at once

    Other examples can be found on JSFiddle and the Bacon.js blog.

    The subscribe function must return a function. Let's call that function unsubscribe. The returned function can be used by the subscriber (directly or indirectly) to unsubscribe from the EventStream. It should release all resources that the subscribe function reserved.

    The sink function may return Bacon.noMore (as well as Bacon.more or any other value). If it returns Bacon.noMore, no further events will be consumed by the subscriber. The subscribe function may choose to clean up all resources at this point (e.g., by calling unsubscribe). This is usually not necessary, because further calls to sink are ignored, but doing so can increase performance in rare cases.

    The EventStream will wrap your subscribe function so that it will only be called when the first stream listener is added, and the unsubscribe function is called only after the last listener has been removed. The subscribe-unsubscribe cycle may of course be repeated indefinitely, so prepare for multiple calls to the subscribe function.

    Type parameters

    • V

      Type of stream elements

    Parameters

    Returns EventStream<V>

fromCallback

  • fromCallback<V>(f: Function, ...args: any[]): EventStream<V>
  • Creates an EventStream from a function that accepts a callback. The function is supposed to call its callback just once. For example:

    Bacon.fromCallback(callback => callback("bacon"))

    This would create a stream that outputs a single value "Bacon!" and ends after that. The use of setTimeout causes the value to be delayed by 1 second.

    You can also give any number of arguments to fromCallback, which will be passed to the function. These arguments can be simple variables, Bacon EventStreams or Properties. For example the following will output "Bacon rules":

    bacon = Bacon.constant('bacon')
    Bacon.fromCallback(function(a, b, callback) {
    callback(a + ' ' + b);
    }, bacon, 'rules').log();

    Type parameters

    • V

    Parameters

    • f: Function
    • Rest ...args: any[]

    Returns EventStream<V>

fromESObservable

  • fromESObservable<V>(_observable: any): EventStream<V>

fromEvent

  • creates an EventStream from events on a DOM EventTarget or Node.JS EventEmitter object, or an object that supports event listeners using on/off methods. You can also pass an optional function that transforms the emitted events' parameters.

    The simple form:

    Bacon.fromEvent(document.body, "click").onValue(function() { alert("Bacon!") })

    Using a binder function:

    Bacon.fromEvent(
    window,
    function(binder, listener) {
    binder("scroll", listener, {passive: true})
    }
    ).onValue(function() {
    console.log(window.scrollY)
    })

    Type parameters

    • V

      Type of stream elements

    Parameters

    Returns EventStream<V>

fromNodeCallback

  • fromNodeCallback<V>(f: Function, ...args: any[]): EventStream<V>
  • Behaves the same way as Bacon.fromCallback, except that it expects the callback to be called in the Node.js convention: callback(error, data), where error is null if everything is fine. For example:

    var Bacon = require('baconjs').Bacon,
    fs = require('fs');
    var read = Bacon.fromNodeCallback(fs.readFile, 'input.txt');
    read.onError(function(error) { console.log("Reading failed: " + error); });
    read.onValue(function(value) { console.log("Read contents: " + value); });

    Type parameters

    • V

    Parameters

    • f: Function
    • Rest ...args: any[]

    Returns EventStream<V>

fromPoll

  • Polls given function with given interval. Function should return Events: either Bacon.Next or Bacon.End. Polling occurs only when there are subscribers to the stream. Polling ends permanently when f returns Bacon.End.

    Type parameters

    • V

      Type of stream elements

    Parameters

    • delay: number

      poll interval in milliseconds

    • poll: PollFunction<V>

      function to be polled

    Returns EventStream<V>

fromPromise

  • Creates an EventStream from a Promise object such as JQuery Ajax. This stream will contain a single value or an error, followed immediately by stream end. You can use the optional abort flag (i.e. ´fromPromise(p, true)´ to have the abort method of the given promise be called when all subscribers have been removed from the created stream. You can also pass an optional function that transforms the promise value into Events. The default is to transform the value into [new Bacon.Next(value), new Bacon.End()]. Check out this example.

    Type parameters

    • V

    Parameters

    • promise: Promise<V>
    • Optional abort: undefined | false | true

      should we call the abort method of the Promise on unsubscribe. This is a nonstandard feature you should probably ignore.

    • Default value eventTransformer: EventTransformer<V> = valueAndEnd

    Returns EventStream<V>

getScheduler

hasValue

  • hasValue<V>(e: Event<V>): e is Value<V>

hasWaiters

  • hasWaiters(): boolean

inTransaction

  • inTransaction(event: Event<any> | undefined, context: any, f: Function, args: any[]): any

interval

  • Repeats the single element indefinitely with the given interval (in milliseconds)

    Type parameters

    • V

      Type of stream elements

    Parameters

    • delay: number

      Repeat delay in milliseconds

    • value: V

      The single value to repeat

    Returns EventStream<V>

isEnd

  • isEnd<V>(e: Event<V>): e is End
  • Returns true if the given event is an End

    Type parameters

    • V

    Parameters

    Returns e is End

isError

  • isError<V>(e: Event<V>): e is Error

isEvent

  • isEvent<V>(e: any): e is Event<V>
  • Returns true if the given object is an Event.

    Type parameters

    • V

    Parameters

    • e: any

    Returns e is Event<V>

isEventSourceFn

  • isEventSourceFn(x: any): x is EventSourceFn
  • Parameters

    • x: any

    Returns x is EventSourceFn

isInTransaction

  • isInTransaction(): boolean

isInitial

  • isInitial<V>(e: Event<V>): e is Initial<V>

isNext

  • isNext<V>(e: Event<V>): e is Next<V>
  • Returns true if the given event is a Next

    Type parameters

    • V

    Parameters

    Returns e is Next<V>

isNone

  • isNone(object: any): boolean

isRawPattern

  • isRawPattern(pattern: Pattern<any>): pattern is RawPattern

isTypedOrRawPattern

  • isTypedOrRawPattern(pattern: Pattern<any>): boolean

lateBindFirst

  • lateBindFirst(f: Function): (Anonymous function)
  • Parameters

    • f: Function

    Returns (Anonymous function)

later

  • Creates a single-element stream that emits given value after given delay and ends.

    Type parameters

    • V

      Type of stream elements

    Parameters

    • delay: number

      delay in milliseconds

    • value: V

      value to be emitted

    Returns EventStream<V>

makeCombinator

mergeAll

  • mergeAll<V>(...streams: (Observable<V> | Observable<V>[])[]): EventStream<V>
  • Merges given array of EventStreams or Properties, by collecting the values from all of the sources into a single EventStream.

    See also merge.

    Type parameters

    • V

    Parameters

    • Rest ...streams: (Observable<V> | Observable<V>[])[]

    Returns EventStream<V>

never

  • Creates an EventStream that immediately ends.

    Type parameters

    • V

      Type of stream elements

    Returns EventStream<V>

none

  • none<T>(): Option<T>

onValues

  • onValues(...args: any[]): Unsub
  • A shorthand for combining multiple sources (streams, properties, constants) as array and assigning the side-effect function f for the values. The following example would log the number 3.

    function f(a, b) { console.log(a + b) }
    Bacon.onValues(Bacon.constant(1), Bacon.constant(2), f)

    Parameters

    • Rest ...args: any[]

    Returns Unsub

once

  • Creates an EventStream that delivers the given single value for the first subscriber. The stream will end immediately after this value. You can also send an Bacon.Error event instead of a value: Bacon.once(new Bacon.Error("fail")).

    Type parameters

    • V

      Type of stream elements

    Parameters

    • value: V | Event<V>

      the value or event to emit

    Returns EventStream<V>

partiallyApplied

  • partiallyApplied(f: Function, applied: any[]): (Anonymous function)

processAfters

  • processAfters(): void

processRawPatterns

  • processRawPatterns(rawPatterns: RawPattern[]): [AnySource[], IndexPattern[]]

repeat

  • repeat<V>(generator: (iteration: number) => undefined | Observable<V>): EventStream<V>
  • Calls generator function which is expected to return an observable. The returned EventStream contains values and errors from the spawned observable. When the spawned observable ends, the generator is called again to spawn a new observable.

    This is repeated until the generator returns a falsy value (such as undefined or false).

    The generator function is called with one argument — iteration number starting from 0.

    Here's an example:

    Bacon.repeat(function(i) {
    if (i < 3) {
    return Bacon.once(i);
    } else {
    return false;
    }
    }).log()

    The example will produce values 0, 1 and 2.

    Type parameters

    • V

      Type of stream elements

    Parameters

    • generator: (iteration: number) => undefined | Observable<V>
        • (iteration: number): undefined | Observable<V>
        • Parameters

          • iteration: number

          Returns undefined | Observable<V>

    Returns EventStream<V>

repeatedly

  • Repeats given elements indefinitely with given interval in milliseconds. For example, repeatedly(10, [1,2,3]) would lead to 1,2,3,1,2,3... to be repeated indefinitely.

    Type parameters

    • V

      Type of stream elements

    Parameters

    • delay: number

      between values, in milliseconds

    • values: (V | Event<V>)[]

      array of values to repeat

    Returns EventStream<V>

retry

  • Used to retry the call when there is an Error event in the stream produced by the source function.

    var triggeringStream, ajaxCall // <- ajaxCall gives Errors on network or server errors
    ajaxResult = triggeringStream.flatMap(function(url) {
    return Bacon.retry({
    source: function(attemptNumber) { return ajaxCall(url) },
    retries: 5,
    isRetryable: function (error) { return error.httpStatusCode !== 404; },
    delay: function(context) { return 100; } // Just use the same delay always
    })
    })

    Type parameters

    • V

    Parameters

    Returns EventStream<V>

sequentially

  • Creates a stream containing given values (given as array). Delivered with given interval in milliseconds.

    Type parameters

    • V

      Type of stream elements

    Parameters

    • delay: number

      between elements, in milliseconds

    • values: (V | Event<V>)[]

    Returns EventStream<V>

setScheduler

  • setScheduler(newScheduler: Scheduler): void

silence

  • Creates a stream that ends after given amount of milliseconds, without emitting any values.

    Type parameters

    • V

      Type of stream elements

    Parameters

    • duration: number

      duration of silence in milliseconds

    Returns EventStream<V>

singleToObservables

  • singleToObservables<T>(x: T | Observable<T> | Observable<T>[]): Observable<T>[]

soonButNotYet

Const spy

  • spy(spy: Spy): number
  • Adds your function as a "spy" that will get notified on all new Observables. This will allow a visualization/analytics tool to spy on all Bacon activity.

    Parameters

    Returns number

symbol

  • symbol(key: string): any
  • Parameters

    • key: string

    Returns any

takeWhileT

toDelayFunction

toOption

  • toOption<V>(v: V | Option<V>): Option<V>
  • Type parameters

    • V

    Parameters

    • v: V | Option<V>

    Returns Option<V>

toProperty

update

  • Creates a Property from an initial value and updates the value based on multiple inputs. The inputs are defined similarly to Bacon.when, like this:

    var result = Bacon.update(
    initial,
    [x,y,z, (previous,x,y,z) => { ... }],
    [x,y,   (previous,x,y) => { ... }])

    As input, each function above will get the previous value of the result Property, along with values from the listed Observables. The value returned by the function will be used as the next value of result.

    Just like in Bacon.when, only EventStreams will trigger an update, while Properties will be just sampled. So, if you list a single EventStream and several Properties, the value will be updated only when an event occurs in the EventStream.

    Here's a simple gaming example:

    let scoreMultiplier = Bacon.constant(1)
    let hitUfo = Bacon.interval(1000)
    let hitMotherShip = Bacon.later(10000)
    let score = Bacon.update(
    0,
    [hitUfo, scoreMultiplier, (score, _, multiplier) => score + 100 * multiplier ],
    [hitMotherShip, (score, _) => score + 2000 ]
    )

    In the example, the score property is updated when either hitUfo or hitMotherShip occur. The scoreMultiplier Property is sampled to take multiplier into account when hitUfo occurs.

    Type parameters

    • Out

    Parameters

    Returns Property<Out>

valueAndEnd

when

  • The when method provides a generalization of the zip function. While zip synchronizes events from multiple streams pairwse, the join patterns used in when allow the implementation of more advanced synchronization patterns.

    Consider implementing a game with discrete time ticks. We want to handle key-events synchronized on tick-events, with at most one key event handled per tick. If there are no key events, we want to just process a tick.

    Bacon.when(
    [tick, keyEvent, function(_, k) { handleKeyEvent(k); return handleTick(); }],
    [tick, handleTick])

    Order is important here. If the [tick] patterns had been written first, this would have been tried first, and preferred at each tick.

    Join patterns are indeed a generalization of zip, and for EventStreams, zip is equivalent to a single-rule join pattern. The following observables have the same output, assuming that all sources are EventStreams.

    Bacon.zipWith(a,b,c, combine)
    Bacon.when([a,b,c], combine)

    Note that Bacon.when does not trigger updates for events from Properties though; if you use a Property in your pattern, its value will be just sampled when all the other sources (EventStreams) have a value. This is useful when you need a value of a Property in your calculations. If you want your pattern to fire for a Property too, you can convert it into an EventStream using property.changes() or property.toEventStream()

    Type parameters

    • O

      result type

    Parameters

    • Rest ...patterns: Pattern<O>[]

      Join patterns

    Returns EventStream<O>

whenDoneWith

withMethodCallSupport

  • withMethodCallSupport(wrapped: Function): (Anonymous function)

withStateMachineT

  • withStateMachineT<In, State, Out>(initState: State, f: StateF<In, State, Out>): Transformer<In, Out>

wrap

  • wrap<V>(obs: Observable<V>): DefaultSource<V>
  • Type parameters

    • V

    Parameters

    • obs: Observable<V>

    Returns DefaultSource<V>

wrappedSubscribe

zipAsArray

  • zipAsArray<V>(...args: (Observable<V> | Observable<V>[])[]): Observable<V[]>
  • Zips the array of EventStreams / Properties in to a new EventStream that will have an array of values from each source as its value. Zipping means that events from each source are combined pairwise so that the 1st event from each source is published first, then the 2nd event from each. The results will be published as soon as there is a value from each source.

    Be careful not to have too much "drift" between streams. If one stream produces many more values than some other excessive buffering will occur inside the zipped observable.

    Example:

    x = Bacon.fromArray([1,2,3])
    y = Bacon.fromArray([10, 20, 30])
    z = Bacon.fromArray([100, 200, 300])
    Bacon.zipAsArray(x, y, z)
    
    # produces values [1, 10, 100], [2, 20, 200] and [3, 30, 300]

    Type parameters

    • V

    Parameters

    • Rest ...args: (Observable<V> | Observable<V>[])[]

    Returns Observable<V[]>

zipWith

  • zipWith<Out>(f: (...any: any[]) => Out, ...streams: Observable<any>[]): EventStream<Out>
  • Like zipAsArray but uses the given n-ary function to combine the n values from n sources, instead of returning them in an Array.

    Type parameters

    • Out

    Parameters

    • f: (...any: any[]) => Out
        • (...any: any[]): Out
        • Parameters

          • Rest ...any: any[]

          Returns Out

    • Rest ...streams: Observable<any>[]

    Returns EventStream<Out>

Object literals

Const $

$: object

JQuery/Zepto integration support

asEventStream

  • asEventStream(eventName: string, selector: string | undefined, eventTransformer: any): EventStream<any>
  • Creates an EventStream from events on a jQuery or Zepto.js object. You can pass optional arguments to add a jQuery live selector and/or a function that processes the jQuery event and its parameters, if given, like this:

    $("#my-div").asEventStream("click", ".more-specific-selector")
    $("#my-div").asEventStream("click", ".more-specific-selector", function(event, args) { return args[0] })
    $("#my-div").asEventStream("click", function(event, args) { return args[0] })

    Note: you need to install the asEventStream method on JQuery by calling init() as in Bacon.$.init($).

    Parameters

    • eventName: string
    • selector: string | undefined
    • eventTransformer: any

    Returns EventStream<any>

init

  • init(jQuery: any): void
  • Installs the asEventStream to the given jQuery/Zepto object (the $ object).

    Parameters

    • jQuery: any

    Returns void

Const GlobalScheduler

GlobalScheduler: object

scheduler

scheduler: Scheduler = defaultScheduler

_

_: object

all

all: all

always

always: always

any

any: any

bind

bind: bind

contains

contains: contains

each

each: each

empty

empty: empty

filter

filter: filter

flatMap

flatMap: flatMap

fold

fold: fold

head

head: head

id

id: id

indexOf

indexOf: indexOfDefault

indexWhere

indexWhere: indexWhere

isFunction

isFunction: isFunction

last

last: last

map

map: map

negate

negate: negate

remove

remove: remove

tail

tail: tail

toArray

toArray: toArray

toFunction

toFunction: toFunction

toString

toString: toString

without

without: without

Generated using TypeDoc