2.0.2 • Published 4 years ago

callbag-lazy v2.0.2

Weekly downloads
3,846
License
MIT
Repository
github
Last release
4 years ago

callbag-lazy

Callbag source for lazy evaluation at subscription time. Weighs 98 bytes (minified & gzipped).

npm install callbag-lazy

Example

window inner width

const lazy = require('callbag-lazy');
const subscribe = require('callbag-subscribe')

const src = lazy(() => window.innerWidth);

const observer = {
  next(v) {
    console.log(`Next(${v})`);
  },
  complete() {
    console.log('Done()');
  }
};

setTimeout(() => subscribe(observer)(src), 2000);
// logs the window width at subscription time then logs 'Done()'

This source is equivalent to the sources below:

const create = require('callbag-create');
const { fromIter, map, pipe } = require('callbag-basics');

const src1 = pipe(
  fromIter([() => window.innerWidth]),
  map(f => f())
);

const src2 = create((sink) => {
  sink(1, window.innerWith);
  sink(2);
});
2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago