Skip to content

Commit

Permalink
Merge pull request #4308 from Polymer/2.0-preview-debouncer-flush
Browse files Browse the repository at this point in the history
Reset the `active` state once the callback runs
  • Loading branch information
Steve Orvell authored Feb 13, 2017
2 parents 12a4bcd + fecb209 commit d6e9e8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/debounce.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
setConfig(asyncModule, cb) {
this._asyncModule = asyncModule;
this._callback = cb;
this._timer = this._asyncModule.run(this._callback);
this._timer = this._asyncModule.run(this.flush);
},

/**
Expand Down
11 changes: 11 additions & 0 deletions test/unit/debounce.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@
});
});

test('flush debouncer', function(done) {
var callback = sinon.spy();
var job = Polymer.Debouncer.debounce(null, Polymer.Async.microTask, callback);

setTimeout(function() {
job.flush();
assert.isTrue(callback.calledOnce, 'callback should be called once');
done();
});
});

test('different debouncers and multiple micro tasks', function(done) {
var callback = sinon.spy();
var job1 = Polymer.Debouncer.debounce(null, Polymer.Async.microTask, callback);
Expand Down

0 comments on commit d6e9e8a

Please sign in to comment.