Skip to content

franciscotln/callbag-lazy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Callbag source for lazy evaluation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published