SUPPORT-9194: replace subscription with listener

This commit is contained in:
gulnaz 2025-05-23 16:06:19 +03:00
parent db71ddab3a
commit 9e5916ca6b

View file

@ -1,9 +1,7 @@
import {AnalyticalScope, Behavior, NotNull, ObjectRef, Text} from "@webbpm/base-package"; import {AnalyticalScope, Behavior, NotNull, ObjectRef, Text} from "@webbpm/base-package";
import {Subscription} from "rxjs";
import {OnDestroy} from "@angular/core";
@AnalyticalScope(Text) @AnalyticalScope(Text)
export class DigitDependentValue extends Behavior implements OnDestroy { export class DigitDependentValue extends Behavior {
@ObjectRef() @ObjectRef()
@NotNull() @NotNull()
@ -17,17 +15,19 @@ export class DigitDependentValue extends Behavior implements OnDestroy {
public otherDigitValue: string; public otherDigitValue: string;
private text: Text; private text: Text;
private subscription: Subscription; private parentValueChangeListener: Function;
private excludedNumbers: number[] = [11, 12, 13, 14]; private excludedNumbers: number[] = [11, 12, 13, 14];
initialize() { initialize() {
super.initialize(); super.initialize();
this.text = this.getScript(Text); this.text = this.getScript(Text);
this.subscription = this.parent.valueChangeEvent.subscribe(value => { this.parentValueChangeListener = () => {
let value = this.parent.getValue();
if (value) { if (value) {
this.text.setValue(this.getValueDependOn(value)); this.text.setValue(this.getValueDependOn(value));
} }
}); };
} }
private getValueDependOn(parentValue: string) { private getValueDependOn(parentValue: string) {
@ -43,7 +43,13 @@ export class DigitDependentValue extends Behavior implements OnDestroy {
: this.otherDigitValue; : this.otherDigitValue;
} }
ngOnDestroy() { bindEvents() {
this.subscription.unsubscribe(); super.bindEvents();
this.parent.addChangeListener(this.parentValueChangeListener);
}
unbindEvents() {
super.unbindEvents();
this.parent.removeChangeListener(this.parentValueChangeListener);
} }
} }