From 9e5916ca6bd4fc46f6571c99e7dd3011c3bf1c72 Mon Sep 17 00:00:00 2001 From: gulnaz Date: Fri, 23 May 2025 16:06:19 +0300 Subject: [PATCH] SUPPORT-9194: replace subscription with listener --- .../component/text/DigitDependentValue.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/frontend/src/ts/ervu_business_metrics/component/text/DigitDependentValue.ts b/frontend/src/ts/ervu_business_metrics/component/text/DigitDependentValue.ts index 9f0a7e9..dac03db 100644 --- a/frontend/src/ts/ervu_business_metrics/component/text/DigitDependentValue.ts +++ b/frontend/src/ts/ervu_business_metrics/component/text/DigitDependentValue.ts @@ -1,9 +1,7 @@ import {AnalyticalScope, Behavior, NotNull, ObjectRef, Text} from "@webbpm/base-package"; -import {Subscription} from "rxjs"; -import {OnDestroy} from "@angular/core"; @AnalyticalScope(Text) -export class DigitDependentValue extends Behavior implements OnDestroy { +export class DigitDependentValue extends Behavior { @ObjectRef() @NotNull() @@ -17,17 +15,19 @@ export class DigitDependentValue extends Behavior implements OnDestroy { public otherDigitValue: string; private text: Text; - private subscription: Subscription; + private parentValueChangeListener: Function; private excludedNumbers: number[] = [11, 12, 13, 14]; initialize() { super.initialize(); this.text = this.getScript(Text); - this.subscription = this.parent.valueChangeEvent.subscribe(value => { + this.parentValueChangeListener = () => { + let value = this.parent.getValue(); + if (value) { this.text.setValue(this.getValueDependOn(value)); } - }); + }; } private getValueDependOn(parentValue: string) { @@ -43,7 +43,13 @@ export class DigitDependentValue extends Behavior implements OnDestroy { : this.otherDigitValue; } - ngOnDestroy() { - this.subscription.unsubscribe(); + bindEvents() { + super.bindEvents(); + this.parent.addChangeListener(this.parentValueChangeListener); + } + + unbindEvents() { + super.unbindEvents(); + this.parent.removeChangeListener(this.parentValueChangeListener); } } \ No newline at end of file