Skip to content

Commit

Permalink
feat(button): add a debounce time option
Browse files Browse the repository at this point in the history
  • Loading branch information
mattp94 authored and rwaldron committed Jul 13, 2020
1 parent b0b1a21 commit dfa5e54
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@ function Button(opts) {
last: null
};

// Create a debounce boundary on event triggers
// this avoids button events firing on
// press noise and false positives
var trigger = Fn.debounce(function(key) {
aliases[key].forEach(function(type) {
this.emit(type);
}, this);
}, 7);

pinValue = typeof opts === "object" ? opts.pin : opts;

Board.Component.call(
Expand Down Expand Up @@ -223,6 +214,11 @@ function Button(opts) {

this.pulldown = opts.pulldown || opts.isPulldown || false;

// `debounceTime` is a duration (milliseconds)
// to prevent button events firing on
// press noise and false positives
this.debounceTime = opts.debounceTime || 7;

// Turns out some button circuits will send
// 0 for up and 1 for down, and some the inverse,
// so we can invert our function with this option.
Expand Down Expand Up @@ -291,6 +287,15 @@ function Button(opts) {
}
});

// Create a debounce boundary on event triggers
// this avoids button events firing on
// press noise and false positives
var trigger = Fn.debounce(function(key) {
aliases[key].forEach(function(type) {
this.emit(type);
}, this);
}, this.debounceTime);

/* istanbul ignore else */
if (typeof this.initialize === "function") {
this.initialize(opts, function(data) {
Expand Down

0 comments on commit dfa5e54

Please sign in to comment.