From 36a7ce3d9be0dd1fa2a0ed5baa5447f73e06c31f Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 5 Jan 2021 15:50:35 +0100 Subject: [PATCH] chore: refactor per comments --- packages/core/ui/core/bindable/index.ts | 23 +++++++++++-------- .../core/ui/list-view/list-view-common.ts | 3 ++- packages/core/ui/repeater/index.ts | 6 ++++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/core/ui/core/bindable/index.ts b/packages/core/ui/core/bindable/index.ts index 2fc659ed0..a7fbe1b7c 100644 --- a/packages/core/ui/core/bindable/index.ts +++ b/packages/core/ui/core/bindable/index.ts @@ -344,7 +344,8 @@ export class Binding { } let newValue = value; - if (!__UI_CUSTOM_FLAVOR__ && this.options.expression) { + if (__UI_CUSTOM_FLAVOR__) { + } else if (this.options.expression) { const changedModel = {}; changedModel[bc.bindingValueKey] = value; changedModel[bc.newPropertyValueKey] = value; @@ -369,6 +370,7 @@ export class Binding { newValue = expressionValue; } + this.updateSource(newValue); } @@ -424,14 +426,7 @@ export class Binding { } } - if (!__UI_CUSTOM_FLAVOR__ && this.options.expression) { - const expressionValue = this._getExpressionValue(this.options.expression, false, undefined); - if (expressionValue instanceof Error) { - Trace.write(expressionValue.message, Trace.categories.Binding, Trace.messageType.error); - } else { - this.updateTarget(expressionValue); - } - } else { + if (__UI_CUSTOM_FLAVOR__ || !this.options.expression) { if (changedPropertyIndex > -1) { const props = sourceProps.slice(changedPropertyIndex + 1); const propsLength = props.length; @@ -446,6 +441,13 @@ export class Binding { this.updateTarget(data.value); } } + } else { + const expressionValue = this._getExpressionValue(this.options.expression, false, undefined); + if (expressionValue instanceof Error) { + Trace.write(expressionValue.message, Trace.categories.Binding, Trace.messageType.error); + } else { + this.updateTarget(expressionValue); + } } // we need to do this only if nested objects are used as source and some middle object has changed. @@ -519,7 +521,8 @@ export class Binding { } private getSourcePropertyValue() { - if (!__UI_CUSTOM_FLAVOR__ && this.options.expression) { + if (__UI_CUSTOM_FLAVOR__) { + } else if (this.options.expression) { const changedModel = {}; changedModel[bc.bindingValueKey] = this.source ? this.source.get() : undefined; const expressionValue = this._getExpressionValue(this.options.expression, false, changedModel); diff --git a/packages/core/ui/list-view/list-view-common.ts b/packages/core/ui/list-view/list-view-common.ts index 6ed46cec0..8e5a875a9 100644 --- a/packages/core/ui/list-view/list-view-common.ts +++ b/packages/core/ui/list-view/list-view-common.ts @@ -26,7 +26,8 @@ export abstract class ListViewBase extends ContainerView implements ListViewDefi public _defaultTemplate: KeyedTemplate = { key: 'default', createView: () => { - if (!__UI_CUSTOM_FLAVOR__ && this.itemTemplate) { + if (__UI_CUSTOM_FLAVOR__) { + } else if (this.itemTemplate) { return Builder.parse(this.itemTemplate, this); } diff --git a/packages/core/ui/repeater/index.ts b/packages/core/ui/repeater/index.ts index 663606a28..630f0be50 100644 --- a/packages/core/ui/repeater/index.ts +++ b/packages/core/ui/repeater/index.ts @@ -129,7 +129,11 @@ export class Repeater extends CustomLayoutView { } if (!viewToAdd) { - viewToAdd = (!__UI_CUSTOM_FLAVOR__ && this.itemTemplate) ? Builder.parse(this.itemTemplate, this) : this._getDefaultItemContent(i); + if (__UI_CUSTOM_FLAVOR__) { + viewToAdd = this._getDefaultItemContent(i) + } else { + viewToAdd = this.itemTemplate ? Builder.parse(this.itemTemplate, this) : this._getDefaultItemContent(i); + } } viewToAdd.bindingContext = dataItem;