flyd-cacheuntil
v1.0.0
Published
Cache a stream's output until triggered by another stream.
Downloads
39
Readme
flyd-cacheUntil
Cache a stream's output until triggered by another stream. Returns an Immutable.List of cached values.
Signature
Stream<E> -> Stream -> Stream<List<E>>
Usage
import flyd from 'flyd';
import cache from 'flyd-cacheuntil';
/* or */
import cacheUntil from 'flyd-cacheuntil';
const stream = flyd.stream();
const trigger = flyd.stream();
const cachedStream = cache(stream).until(trigger);
/* or */
const cachedStream = cacheUntil(trigger, stream);
flyd.on(x => {
console.log('Output:', x.toJS());
}, cachedStream);
stream(1)(2)(3)(4)(5);
trigger(true);
stream('a')('b')('c')('d')('e');
trigger(true);
// Output: List [ 1, 2, 3, 4, 5 ]
// Output: List [ "a", "b", "c", "d", "e" ]