Skip to content

Commit

Permalink
refactor: reduce item renderer calls in combo box (#8173)
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker authored Nov 20, 2024
1 parent 3ebe976 commit 0f88392
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/combo-box/src/vaadin-combo-box-data-provider-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>
this.__dataProviderInitialized = true;

if (this.dataProvider) {
this.requestContentUpdate();
this.__synchronizeControllerState();
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>
const { rootCache } = this.__dataProviderController;
rootCache.items = [...rootCache.items];

this.requestContentUpdate();
this.__synchronizeControllerState();

if (!this.opened && !this._isInputFocused()) {
this._commitValue();
Expand All @@ -183,7 +183,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>

this.__dataProviderController.clearCache();

this.requestContentUpdate();
this.__synchronizeControllerState();

if (this._shouldFetchData()) {
this._forceNextRequest = false;
Expand All @@ -206,7 +206,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>
// The controller adds new placeholders to the cache through mutation,
// so we need to create a new array to trigger filteredItems observers.
rootCache.items = [...rootCache.items];
this.requestContentUpdate();
this.__synchronizeControllerState();
}
}

Expand All @@ -224,19 +224,19 @@ export const ComboBoxDataProviderMixin = (superClass) =>
const { rootCache } = this.__dataProviderController;
if (rootCache.items !== items) {
rootCache.items = items;
this.requestContentUpdate();
this.__synchronizeControllerState();
}
}
}

/**
* Synchronizes the controller's state with the component, which can be
* out of sync after the controller receives new data from the data provider
* or if the state in the controller is directly manupulated.
* or if the state in the controller is directly manipulated.
*
* @override
* @private
*/
requestContentUpdate() {
__synchronizeControllerState() {
// When the data provider isn't initialized, it means the content update was requested
// by an observer before the `ready()` callback. In such cases, some properties
// in the data provider controller might still be uninitialized, so it's not safe
Expand All @@ -248,8 +248,6 @@ export const ComboBoxDataProviderMixin = (superClass) =>
this.filteredItems = rootCache.items;
this.loading = this.__dataProviderController.isLoading();
}

super.requestContentUpdate();
}

/** @private */
Expand Down

0 comments on commit 0f88392

Please sign in to comment.