You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: projects/www/src/app/pages/guide/eslint-plugin/rules/no-store-subscription.md
+62-10Lines changed: 62 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,35 +13,87 @@ Using the `async` pipe is preferred over `store` subscription.
13
13
14
14
## Rule Details
15
15
16
+
This rule prevents manual subscriptions to the store, which can lead to memory leaks if not properly unsubscribed. Using the `async` pipe is the recommended approach because Angular automatically handles the subscription and unsubscription, keeping your component code cleaner and preventing memory leaks.
17
+
18
+
### Why Avoid Store Subscriptions?
19
+
20
+
⚠️ **Problems with manual store subscriptions:**
21
+
22
+
- Creates a manual subscription that must be explicitly unsubscribed (e.g., using `takeUntil`, `async`, or `destroyRef`), otherwise it will persist beyond the component's lifecycle causing memory leaks
23
+
Will not trigger change detection in zoneless mode. Users have to ensure it otherwise.
24
+
25
+
✅ **Benefits of using the async pipe:**
26
+
27
+
- No manual subscription management - Angular's `async` pipe handles subscription and unsubscription automatically
28
+
- Keeps the component more declarative
29
+
16
30
Examples of **incorrect** code for this rule:
17
31
32
+
1. Subscribing to the store to get data from a selector
0 commit comments