arch-js / arch-cli

Command line tool for the Arch framework
1 stars 2 forks source link

Debounce built into `on-change` or Arch #18

Closed chrisvfritz closed 9 years ago

chrisvfritz commented 9 years ago

I would love a built-in way of debouncing an on-change callback.

cursor.on-change!.debounce 500, -> ...
# or
cursor.on-change arch.helpers.debounce -> ...
# or
curser.on-change 500, -> ...

The last one would be my favorite, since debounces are so common (at least in my uses). If the first argument is an integer instead of a function, the second parameter (the callback) should be debounced by that integer (in milliseconds like set-timeout).

If you need a debounce implementation in LiveScript, this is what I currently use:

(wait, func) -->
  timeout = undefined
  !->
    context = @
    args = arguments
    later = !->
      timeout := null
      func.apply context, args
    clear-timeout timeout
    timeout := set-timeout later, wait
chrisvfritz commented 9 years ago

Wrong repo! Very sorry.