@@ -65,33 +65,21 @@ export function flatten(sync, async, fn) {
6565
6666/**
6767 * Captures the current effect context so that we can restore it after
68- * some asynchronous work has happened if `track` is true (so that e.g.
69- * `await a + b` causes `b` to be registered as a dependency).
70- *
71- * If `track` is false, we just take a note of which async derived
72- * brought us here, so that we can emit a `async_reactivity_loss`
73- * warning when it's appropriate to do so.
74- *
75- * @param {boolean } track
68+ * some asynchronous work has happened (so that e.g. `await a + b`
69+ * causes `b` to be registered as a dependency).
7670 */
77- export function capture ( track = true ) {
71+ function capture ( ) {
7872 var previous_effect = active_effect ;
7973 var previous_reaction = active_reaction ;
8074 var previous_component_context = component_context ;
8175
82- if ( DEV && ! track ) {
83- var previous_async_effect = current_async_effect ;
84- }
85-
8676 return function restore ( ) {
87- if ( track ) {
88- set_active_effect ( previous_effect ) ;
89- set_active_reaction ( previous_reaction ) ;
90- set_component_context ( previous_component_context ) ;
91- }
77+ set_active_effect ( previous_effect ) ;
78+ set_active_reaction ( previous_reaction ) ;
79+ set_component_context ( previous_component_context ) ;
9280
9381 if ( DEV ) {
94- set_from_async_derived ( track ? null : previous_async_effect ) ;
82+ set_from_async_derived ( null ) ;
9583 }
9684
9785 // prevent the active effect from outstaying its welcome
@@ -106,11 +94,10 @@ export function capture(track = true) {
10694 * `await a + b` becomes `(await $.save(a))() + b`
10795 * @template T
10896 * @param {Promise<T> } promise
109- * @param {boolean } [track]
11097 * @returns {Promise<() => T> }
11198 */
112- export async function save ( promise , track = true ) {
113- var restore = capture ( track ) ;
99+ export async function save ( promise ) {
100+ var restore = capture ( ) ;
114101 var value = await promise ;
115102
116103 return ( ) => {
@@ -119,6 +106,23 @@ export async function save(promise, track = true) {
119106 } ;
120107}
121108
109+ /**
110+ * Reset `current_async_effect` after the `promise` resolves, so
111+ * that we can emit `await_reactivity_loss` warnings
112+ * @template T
113+ * @param {Promise<T> } promise
114+ * @returns {Promise<() => T> }
115+ */
116+ export async function track_reactivity_loss ( promise ) {
117+ var previous_async_effect = current_async_effect ;
118+ var value = await promise ;
119+
120+ return ( ) => {
121+ set_from_async_derived ( previous_async_effect ) ;
122+ return value ;
123+ } ;
124+ }
125+
122126function unset_context ( ) {
123127 set_active_effect ( null ) ;
124128 set_active_reaction ( null ) ;
0 commit comments