Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move the BehaviorSubject init into the constructor #8132

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-chefs-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/core-app-api': patch
---

move the BehaviorSubject init into the constructor
39 changes: 21 additions & 18 deletions packages/core-app-api/src/lib/subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,34 +121,37 @@ export class PublishSubject<T>
*
* See http://reactivex.io/documentation/subject.html
*/

export class BehaviorSubject<T>
implements Observable<T>, ZenObservable.SubscriptionObserver<T>
{
private isClosed = false;
private isClosed: boolean;
private currentValue: T;
private terminatingError?: Error;
private terminatingError: Error | undefined;
private readonly observable: Observable<T>;

constructor(value: T) {
this.isClosed = false;
this.currentValue = value;
}

private readonly observable = new ObservableImpl<T>(subscriber => {
if (this.isClosed) {
if (this.terminatingError) {
subscriber.error(this.terminatingError);
} else {
subscriber.complete();
this.terminatingError = undefined;
this.observable = new ObservableImpl<T>(subscriber => {
if (this.isClosed) {
if (this.terminatingError) {
subscriber.error(this.terminatingError);
} else {
subscriber.complete();
}
return () => {};
}
return () => {};
}

subscriber.next(this.currentValue);
subscriber.next(this.currentValue);

this.subscribers.add(subscriber);
return () => {
this.subscribers.delete(subscriber);
};
});
this.subscribers.add(subscriber);
return () => {
this.subscribers.delete(subscriber);
};
});
}

private readonly subscribers = new Set<
ZenObservable.SubscriptionObserver<T>
Expand Down