Skip to content

Commit

Permalink
internal subscription cancelled when provider is reset
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasayush committed Mar 29, 2021
1 parent fa51f3d commit 5ad070d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion react-providerx/src/observableProvider/autoDispose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class AutoDisposeObservableProvider<T> {
observableCreator
ref: ProviderReference
_observable$: Observable<T>
_internalSubscription?: Subscription

constructor(observableCreator: (ref: ProviderReference) => Observable<T>) {
this.observableCreator = observableCreator
Expand Down Expand Up @@ -44,7 +45,7 @@ export class AutoDisposeObservableProvider<T> {
if(this._observable$ === null) {
throw 'observableCreator cannot return null. It must return an instance of Observable'
}
this._observable$.subscribe(
this._internalSubscription = this._observable$.subscribe(
(val: T) => {
this._valueSubject$.next(val as any)
this._errorSubject$.next(null as any)
Expand All @@ -57,6 +58,10 @@ export class AutoDisposeObservableProvider<T> {
}

_reset() {
if(this._internalSubscription !== undefined) {
console.log('unsubscribing')
this._internalSubscription.unsubscribe()
}
this._valueSubject$ = new BehaviorSubject(null)
this._errorSubject$ = new BehaviorSubject(null)
}
Expand Down

0 comments on commit 5ad070d

Please sign in to comment.