Change the way subscriptions are done
Previously, we would add a new subscription controller each time
connectedCallback runs. Instead we change the API for the subscribe
method to take a function to return the observable to subscribe to. This
way, the subscribe function can be called from the constructor,
guaranteeing we're only subscribing once. In addition, the subscribe
method throws an error in case subscriptions are attempted when the
component is connected.
Release-Notes: skip
Change-Id: Ie40d7459d6852ac767bd62fee370d0d8e5130a61
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index c460ad7..3e4a555 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -248,27 +248,36 @@
});
}
}
- }
-
- override connectedCallback() {
- super.connectedCallback();
subscribe(
this,
- this.configModel().repoCommentLinks$,
+ () => this.configModel().repoCommentLinks$,
x => (this.commentLinks = x)
);
- subscribe(this, this.userModel.account$, x => (this.account = x));
- subscribe(this, this.userModel.isAdmin$, x => (this.isAdmin = x));
-
- subscribe(this, this.getChangeModel().repo$, x => (this.repoName = x));
subscribe(
this,
- this.getChangeModel().changeNum$,
+ () => this.userModel.account$,
+ x => (this.account = x)
+ );
+ subscribe(
+ this,
+ () => this.userModel.isAdmin$,
+ x => (this.isAdmin = x)
+ );
+
+ subscribe(
+ this,
+ () => this.getChangeModel().repo$,
+ x => (this.repoName = x)
+ );
+ subscribe(
+ this,
+ () => this.getChangeModel().changeNum$,
x => (this.changeNum = x)
);
subscribe(
this,
- this.autoSaveTrigger$.pipe(debounceTime(AUTO_SAVE_DEBOUNCE_DELAY_MS)),
+ () =>
+ this.autoSaveTrigger$.pipe(debounceTime(AUTO_SAVE_DEBOUNCE_DELAY_MS)),
() => {
this.autoSave();
}