Show:

Stream listens to resize, start, update and end events and emits start, update and end events. Resize events get unified with start, update, and end events depending on when they are fired within Samsara's engine cycle.

If listening to multiple sources, Stream emits a single event per Engine cycle.

Constructor

Streams.Stream

(
  • [options]
)

Parameters:

  • [options] Object optional

    Options

    • [start] Function optional

      Custom logic to map the start event

    • [update] Function optional

      Custom logic to map the update event

    • [end] Function optional

      Custom logic to map the end event

Example:

 var position = new Transitionable([0,0]);
         var size = new EventEmitter();
        
         var translationStream = Stream.lift(function(position, size){
             var translation = [
                 position[0] + size[0],
                 position[1] + size[1]
             ];
        
             return Transform.translate(translation);
         }, [positionStream, sizeStream]);
        
         translationStream.on('start', function(transform){
             console.log(transform);
         });
        
         translationStream.on('update', function(transform){
             console.log(transform);
         });
        
         translationStream.on('end', function(transform){
             console.log(transform);
         });
        
         position.set([100, 50], {duration : 500});
         size.emit('resize', [100,100]);

Item Index

Methods

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

lift

(
  • map
  • streams
)
static

Lift is like map, except it maps several event sources, not only one.

Parameters:

Example:

 var liftedStream = Stream.lift(function(payload1, payload2){
                         return payload1 + payload2;
                     }, [stream2, stream2]);
                    
                     liftedStream.on('name'), function(data){
                         // data = 3;
                     });
                    
                     stream2.emit('name', 1);
                     stream2.emit('name', 2);

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

merge

(
  • streams
)
static

Batches events for provided object of streams in {key : stream} pairs. Emits one event per Engine cycle.

Parameters:

  • streams Object

    Dictionary of resize streams

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:

split

(
  • splitterFn
)

Inherited from Streams.SimpleStream:

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

Parameters: