| 32 | } |
| 33 | |
| 34 | class SubscribableStrategy implements SubscriptionStrategy { |
| 35 | createSubscription( |
| 36 | async: Subscribable<any>, |
| 37 | updateLatestValue: any, |
| 38 | onError: (e: unknown) => void, |
| 39 | ): Unsubscribable { |
| 40 | // Subscription can be side-effectful, and we don't want any signal reads which happen in the |
| 41 | // side effect of the subscription to be tracked by a component's template when that |
| 42 | // subscription is triggered via the async pipe. So we wrap the subscription in `untracked` to |
| 43 | // decouple from the current reactive context. |
| 44 | // |
| 45 | // `untracked` also prevents signal _writes_ which happen in the subscription side effect from |
| 46 | // being treated as signal writes during the template evaluation (which throws errors). |
| 47 | return untracked(() => |
| 48 | async.subscribe({ |
| 49 | next: updateLatestValue, |
| 50 | error: onError, |
| 51 | }), |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | dispose(subscription: Unsubscribable): void { |
| 56 | // See the comment in `createSubscription` above on the use of `untracked`. |
| 57 | untracked(() => subscription.unsubscribe()); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | class PromiseStrategy implements SubscriptionStrategy { |
| 62 | createSubscription( |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…