Show:

Accumulator is a Stream that accumulates a value given by a number or array of numbers.

It emits start, update and end events.

Constructor

Streams.Accumulator

(
  • [sum]
  • [options]
)

Parameters:

  • [sum] Number | Array optional

    Initial value

  • [options] Object optional

    Options

    • [min] Number optional

      Set a minimum value

    • [max] Number optional

      Set a maximum value

Example:

 var accumulator = new Accumulator(0);
        
         // this gives the total displacement of mouse input
         accumulator.subscribe(mouseInput.pluck('delta'));

Item Index

Methods

filter

(
  • filterFn
)

Inherited from Streams.SimpleStream:

Filter converts the current stream into a new stream that only emits if the filter condition is satisfied. The function should return a Boolean.

Parameters:

  • filterFn Function
    Function to filter event payload

get

() Number

Returns current accumulated value.

Returns:

map

(
  • mapperFn
)

Inherited from Streams.SimpleStream:

Map converts the current stream into a new stream with a modified (mapped) data payload.

Parameters:

  • mapperFn Function
    Function to map event payload

pluck

(
  • key
)

Inherited from Streams.SimpleStream:

Pluck is an opinionated mapper. It projects a Stream onto one of its return values. Useful if a Stream returns an array or an object.

Parameters:

set

(
  • sum
  • [silent=false]
)

Set accumulated value.

Parameters:

  • sum Number

    Current value

  • [silent=false] Boolean optional

    Flag to suppress events

split

(
  • splitterFn
)

Inherited from Streams.SimpleStream:

Split maps one of several streams based on custom logic. The function should return an EventEmitter.

Parameters: