Git Product home page Git Product logo

pull-debounce's Introduction

pull-debounce

NPM

debounce for pull-streams

Example

var pull = require('pull-stream')
var debounce = require('pull-debounce')

function timedSource(data) {
  return pull(
    pull.values(data),
    pull.asyncMap(function(item, cb) {
      setTimeout(function() {
        cb(null, item[1])
      }, item[0]);
    })
  )
}

pull(
  timedSource([
    [0,   0],
    [250, 1],
    [10,  2],
    [250, 3],
    [2000,4],
    [10,  5]
  ]),
  debounce(200),
  pull.log()
)
// => 0,2,3,5

Credits

Many thanks to @amsross, who provided valuable feedback, bug reports and code

License

MIT

pull-debounce's People

Contributors

regular avatar

Watchers

 avatar

pull-debounce's Issues

Clash of the debouncers

Rather than pollute pull-stream/pull-stream-docs#27 with this discussion, I'm opening this issue.

I have a feeling that our two implementations of debounce may serve two different purposes.

Your implementation using pull-window will return the last data event in one window regardless of silence on the wire within or after one window. My implementation will wait until there has been silence on the wire for the length of one window, at which time it will return the last data event. As a result, my implementation will not pass your tests, and your implementation will not pass my tests.

My understanding is that the pull-window implementation is not correct according to what I interpret debouncing to mean. Do you agree or am I misinterpreting what is really going on?

(re: https://css-tricks.com/the-difference-between-throttling-and-debouncing/#article-header-id-1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.