import "./scan"; import Observable, { Property } from "./observable"; /** * [Update](#update) pattern consisting of a single EventStream and a accumulator function. */ export declare type UpdatePattern1 = [Observable, O | ((acc: O, a: I1) => O)]; /** * [Update](#update) pattern consisting of 2 Observables and an accumulrator function. At least one of the Observables must be an EventStream. */ export declare type UpdatePattern2 = [Observable, Observable, O | ((acc: O, a: I1, b: I2) => O)]; /** * [Update](#update) pattern consisting of 3 Observables and an accumulrator function. At least one of the Observables must be an EventStream. */ export declare type UpdatePattern3 = [Observable, Observable, Observable, O | ((acc: O, a: I1, b: I2, c: I3) => O)]; /** * [Update](#update) pattern consisting of 4 Observables and an accumulrator function. At least one of the Observables must be an EventStream. */ export declare type UpdatePattern4 = [Observable, Observable, Observable, Observable, O | ((acc: O, a: I1, b: I2, c: I3, d: I4) => O)]; /** * [Update](#update) pattern consisting of 5 Observables and an accumulrator function. At least one of the Observables must be an EventStream. */ export declare type UpdatePattern5 = [Observable, Observable, Observable, Observable, Observable, O | ((acc: O, a: I1, b: I2, c: I3, d: I4, e: I5) => O)]; /** * [Update](#update) pattern consisting of 6 Observables and an accumulrator function. At least one of the Observables must be an EventStream. */ export declare type UpdatePattern6 = [Observable, Observable, Observable, Observable, Observable, Observable, O | ((acc: O, a: I1, b: I2, c: I3, d: I4, e: I5, f: I6) => O)]; /** * [Update](#update) pattern type, allowing up to 6 sources per pattern. */ export declare type UpdatePattern = UpdatePattern1 | UpdatePattern2 | UpdatePattern3 | UpdatePattern4 | UpdatePattern5 | UpdatePattern6; /** Creates a Property from an initial value and updates the value based on multiple inputs. The inputs are defined similarly to [`Bacon.when`](#bacon-when), like this: ```js 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`](#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: ```js 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. * @param initial * @param {UpdatePattern} patterns * @returns {Property} */ export declare function update(initial: Out, ...patterns: UpdatePattern[]): Property;