paldepind / flyd

The minimalistic but powerful, modular, functional reactive programming library in JavaScript.
MIT License
1.56k stars 85 forks source link

Rx module #58

Closed cocodrino closed 6 years ago

cocodrino commented 9 years ago

Hi @paldepind I think than would be nice provide a rx module with the most used Rx functions, they're just only a bunch of basic functions

http://rxmarbles.com

could you give me an implementation of debounce function?..I did my own but I consider the result pretty poor, would be nice watch the correct implementation.

thanks!

paldepind commented 9 years ago

Hello @cocodrino

What exactly do you mean with a Rx module? How many of the Rx functions should it contain?

For an implementation of a debounce function you might get inspiration from the afterSilence. I'd like to see your implementation :)

anodynos commented 6 years ago

Also check https://github.com/bertofer/flyd-debounceTime

nordfjord commented 6 years ago

debounce could be implemented using the composition of afterSilence, and last:

const last = xs => xs[xs.length - 1];
const debounceTime = time => value$ => value$
  .pipe(afterSilence(time))
  .map(last)

Or using chain:

const afterTime = time => value => {
  const value$ = flyd.stream();
  setTimeout(()=> value$(value), time);
  return value$;
};

const debounceTime = time => value$ => value$
  .chain(afterTime(time))

I think a great thing about flyd is how minimal it is.