Skip to content

Commit

Permalink
move the BehaviorSubject init into the constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
  • Loading branch information
freben committed Nov 18, 2021
1 parent 770b5ed commit 475edb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
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

0 comments on commit 475edb5

Please sign in to comment.