callbag-lazy

2.0.2 • Public • Published

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);
});

Readme

Keywords

Package Sidebar

Install

npm i callbag-lazy

Weekly Downloads

4,320

Version

2.0.2

License

MIT

Unpacked Size

3.42 kB

Total Files

6

Last publish

Collaborators

  • francisco.tln