Streams.Stream Class
samsara/streams/Stream.js:20
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:
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]);
Methods
filter
-
filterFn
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:
-
filterFnFunctionFunction to filter event payload
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:
-
mapperFnFunctionFunction to map event payload
merge
-
streams
Batches events for provided object of streams in {key : stream} pairs. Emits one event per Engine cycle.
Parameters:
-
streamsObjectDictionary of
resizestreams
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 an object.
split
-
splitterFn
Split maps one of several streams based on custom logic. The function should return an EventEmitter.
Parameters:
-
splitterFnFunctionSplitter function