debounce change events

This commit is contained in:
Niels Lyngsø
2024-04-11 11:45:31 +02:00
committed by Jacob Overgaard
parent 3e891890d1
commit fd70784078

View File

@@ -76,18 +76,27 @@ export class UmbPropertyEditorUIBlockGridElement extends UmbLitElement implement
// TODO: Prevent initial notification from these observes:
this.observe(this.#context.layouts, (layouts) => {
this._value = { ...this._value, layout: { [UMB_BLOCK_GRID_PROPERTY_EDITOR_ALIAS]: layouts } };
this.dispatchEvent(new UmbPropertyValueChangeEvent());
this.#fireChangeEvent();
});
this.observe(this.#context.contents, (contents) => {
this._value = { ...this._value, contentData: contents };
this.dispatchEvent(new UmbPropertyValueChangeEvent());
this.#fireChangeEvent();
});
this.observe(this.#context.settings, (settings) => {
this._value = { ...this._value, settingsData: settings };
this.dispatchEvent(new UmbPropertyValueChangeEvent());
this.#fireChangeEvent();
});
}
#debounceChangeEvent?: boolean;
#fireChangeEvent = async () => {
if (this.#debounceChangeEvent) return;
this.#debounceChangeEvent = true;
await Promise.resolve();
this.dispatchEvent(new UmbPropertyValueChangeEvent());
this.#debounceChangeEvent = false;
};
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
super.firstUpdated(_changedProperties);