-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(store): complete action results on destroy
In this commit, we perform some minor refactoring by replacing the implementation of the `OnDestroy` interface with the use of `ApplicationRef` in the constructor to avoid creating redundant methods. Additionally, we complete the `InternalDispatchedActionResults` once the application is destroyed to ensure there are no active subscribers after resources have been cleaned up.
- Loading branch information
Showing
6 changed files
with
46 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ApplicationRef, inject, Injectable } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
|
||
import type { ActionContext } from '../actions-stream'; | ||
|
||
/** | ||
* Internal Action result stream that is emitted when an action is completed. | ||
* This is used as a method of returning the action result to the dispatcher | ||
* for the observable returned by the dispatch(...) call. | ||
* The dispatcher then asynchronously pushes the result from this stream onto the main action stream as a result. | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class InternalDispatchedActionResults extends Subject<ActionContext> { | ||
constructor() { | ||
super(); | ||
|
||
// Complete the subject once the root injector is destroyed to ensure | ||
// there are no active subscribers that would receive events or perform | ||
// any actions after the application is destroyed. | ||
const appRef = inject(ApplicationRef); | ||
appRef.onDestroy(() => this.complete()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters