Ember.streams.Ember.stream Class
Module: ember-metal
Show:
chain
(value, fn)
Object|Stream
private
Generate a new stream by providing a source stream and a function that can be used to transform the stream's value. In the case of a non-stream object, returns the result of the function.
The value to transform would typically be available to the function you pass
to chain()
via scope. For example:
1 2 3 4 5 6 |
var source = ...; // stream returning a number // or a numeric (non-stream) object var result = chain(source, function() { var currentValue = read(source); return currentValue + 1; }); |
In the example, result is a stream if source is a stream, or a number of source was numeric.
Parameters:
- value Object|Stream
- A stream or non-stream object.
- fn Function
- Function to be run when the stream value changes, or to be run once in the case of a non-stream object.
Returns:
- Object|Stream
- In the case of a stream `value` parameter, a new stream that will be updated with the return value of the provided function `fn`. In the case of a non-stream object, the return value of the provided function `fn`.