Streams.Stream Class
src/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:
-
filterFn
FunctionFunction to filter event payload
map
-
mapperFn
Map converts the current stream into a new stream with a modified (mapped) data payload.
Parameters:
-
mapperFn
FunctionFunction to map event payload
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 an object.
split
-
splitterFn
Split maps one of several streams based on custom logic. The function should return an EventEmitter.
Parameters:
-
splitterFn
FunctionSplitter function