From bae776eca807e041bfc4396b6f9b44df3f75b92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 11 Oct 2024 23:59:29 +0200 Subject: [PATCH] remove return and clean up --- .../element-property-dataset.context.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content/property-dataset-context/element-property-dataset.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content/property-dataset-context/element-property-dataset.context.ts index 219f2134ba..ac92247246 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content/property-dataset-context/element-property-dataset.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content/property-dataset-context/element-property-dataset.context.ts @@ -82,6 +82,7 @@ export abstract class UmbElementPropertyDatasetContext< this.observe( this._dataOwner.structure.contentTypeProperties, (props: UmbPropertyTypeModel[]) => { + console.log('props', props); const map = props.map((prop) => ({ alias: prop.alias, variantId: this.#createPropertyVariantId(prop) })); this.#propertyVariantIdMap.setValue(map); // Resolve promise, to let the once waiting on this know. @@ -166,11 +167,14 @@ export abstract class UmbElementPropertyDatasetContext< ): Promise | undefined> { await this._dataOwner.isLoaded(); await this.#propertyVariantIdPromise; - const propVariantId = this.#propertyVariantIdMap.getValue().find((x) => x.alias === propertyAlias); - if (propVariantId) { - return this._dataOwner.propertyValueByAlias(propertyAlias, propVariantId.variantId); - } - return; + return mergeObservables( + [await this.propertyVariantId(propertyAlias), this._dataOwner.values], + ([variantId, values]) => { + return variantId + ? (values?.find((x) => x?.alias === propertyAlias && variantId.compare(x))?.value as ReturnType) + : undefined; + }, + ); } // TODO: Refactor: Not used currently, but should investigate if we can implement this, to spare some energy. @@ -203,9 +207,9 @@ export abstract class UmbElementPropertyDatasetContext< async setPropertyValue(propertyAlias: string, value: PromiseLike) { this._dataOwner.initiatePropertyValueChange(); await this.#propertyVariantIdPromise; - const propVariantId = this.#propertyVariantIdMap.getValue().find((x) => x.alias === propertyAlias); + const propVariantId = this.#propertyVariantIdMap.getValue().find((x) => x.alias === propertyAlias)?.variantId; if (propVariantId) { - return this._dataOwner.setPropertyValue(propertyAlias, await value, propVariantId.variantId); + await this._dataOwner.setPropertyValue(propertyAlias, await value, propVariantId); } this._dataOwner.finishPropertyValueChange(); } @@ -213,5 +217,6 @@ export abstract class UmbElementPropertyDatasetContext< override destroy() { super.destroy(); this.#propertyVariantIdMap.destroy(); + (this.#propertyVariantIdMap as unknown) = undefined; } }