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 {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);
}
}