Skip to content

Commit b3ad2a6

Browse files
nielslyngsoeiOvergaard
authored andcommitted
debounce change events
1 parent b5f2733 commit b3ad2a6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/packages/block/block-grid/property-editors/block-grid-editor/property-editor-ui-block-grid.element.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,27 @@ export class UmbPropertyEditorUIBlockGridElement extends UmbLitElement implement
7676
// TODO: Prevent initial notification from these observes:
7777
this.observe(this.#context.layouts, (layouts) => {
7878
this._value = { ...this._value, layout: { [UMB_BLOCK_GRID_PROPERTY_EDITOR_ALIAS]: layouts } };
79-
this.dispatchEvent(new UmbPropertyValueChangeEvent());
79+
this.#fireChangeEvent();
8080
});
8181
this.observe(this.#context.contents, (contents) => {
8282
this._value = { ...this._value, contentData: contents };
83-
this.dispatchEvent(new UmbPropertyValueChangeEvent());
83+
this.#fireChangeEvent();
8484
});
8585
this.observe(this.#context.settings, (settings) => {
8686
this._value = { ...this._value, settingsData: settings };
87-
this.dispatchEvent(new UmbPropertyValueChangeEvent());
87+
this.#fireChangeEvent();
8888
});
8989
}
9090

91+
#debounceChangeEvent?: boolean;
92+
#fireChangeEvent = async () => {
93+
if (this.#debounceChangeEvent) return;
94+
this.#debounceChangeEvent = true;
95+
await Promise.resolve();
96+
this.dispatchEvent(new UmbPropertyValueChangeEvent());
97+
this.#debounceChangeEvent = false;
98+
};
99+
91100
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
92101
super.firstUpdated(_changedProperties);
93102

0 commit comments

Comments
 (0)