Skip to content

Commit

Permalink
perf: Debounce offset height measure (#495) (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Sep 1, 2020
1 parent 1ce7092 commit 238ed4a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vaadin-text-field-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,11 @@

/** @private */
__observeOffsetHeight() {
this._dispatchIronResizeEventIfNeeded('Height', this.offsetHeight);
this.__observeOffsetHeightDebouncer = Polymer.Debouncer.debounce(
this.__observeOffsetHeightDebouncer,
Polymer.Async.animationFrame, () => {
this._dispatchIronResizeEventIfNeeded('Height', this.offsetHeight);
});
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/text-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@
describe(`resize notification ${condition}`, () => {
let textField, spy;

function flushTextField(textField) {
textField.__observeOffsetHeightDebouncer.flush();
}

beforeEach(() => {
textField = fixture(`default${fixtureName}`);
spy = sinon.spy();
Expand All @@ -603,7 +607,9 @@
}, 1000);

textField.errorMessage = 'Error';
flushTextField(textField);
textField.invalid = true;
flushTextField(textField);
});

it('should dispatch `iron-resize` event on error message height change', done => {
Expand All @@ -614,17 +620,22 @@

// Long message that spans on multiple lines
textField.errorMessage = [...new Array(42)].map(() => 'bla').join(' ');
flushTextField(textField);

expect(spy).to.be.calledOnce;
done();
}, 1000);

textField.errorMessage = 'Error';
flushTextField(textField);
textField.invalid = true;
flushTextField(textField);
});

it('should dispatch `iron-resize` event on label height change', () => {
flushTextField(textField);
textField.label = 'Label';
flushTextField(textField);
expect(spy).to.be.calledOnce;
});
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 238ed4a

Please sign in to comment.