Streams.Stream Class
samsara/streams/Stream.js:19
Stream listens to start
, update
and end
events and
emits start
, update
and end
events.
If listening to multiple sources, Stream emits a single event per Engine cycle.
Constructor
Streams.Stream
-
[options]
Parameters:
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});
Methods
filter
-
filterFn
Filter converts the current stream into a new stream that only emits if the filter condition is satisfied. The filter function should return a Boolean value.
Parameters:
-
filterFn
FunctionFunction to filter event payload
Returns:
stream Filtered stream
lift
-
map
-
streams
Lift is like map, except it maps several event sources, not only one.
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
Map converts the current stream into a new stream with a modified (mapped) data payload.
Parameters:
-
mapperFn
FunctionFunction to map event payload
Returns:
stream Mapped stream
merge
-
streams
Batches events for provided object of streams in {key : stream} pairs. Emits one event per Engine cycle.
Parameters:
-
streams
ObjectDictionary of
resize
streams
pluck
-
key
Pluck is an opinionated mapper. It projects a Stream onto one of its return values.
Useful if a Stream returns an array or object.
Returns:
stream Plucked stream
split
-
splitterFn
Split maps one of several streams based on custom logic. The splitter function should return an EventEmitter type.
Parameters:
-
splitterFn
FunctionSplitter function