Streams.SimpleStream Class
samsara/streams/SimpleStream.js:9
A SimpleStream wraps an EventHandler and provides convenience
methods of map
, filter
, split
, and pluck
to
transform one stream into another.
Constructor
Streams.SimpleStream
()
private
Example:
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
lift
-
map
-
streams
Lift is like map, except it maps several event sources, not only one.
Example:
var liftedStream = SimpleStream.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
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