File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -105,12 +105,31 @@ export type HandleWarn = (msg: string, ...args: any[]) => void
105105const cleanupMap : WeakMap < ReactiveEffect , ( ( ) => void ) [ ] > = new WeakMap ( )
106106let activeEffect : ReactiveEffect | undefined = undefined
107107
108+ /**
109+ * Returns the current active effect if there is one.
110+ */
111+ export function getCurrentEffect ( ) {
112+ return activeEffect
113+ }
114+
115+ /**
116+ * Registers a cleanup callback on the current active effect. This
117+ * registered cleanup callback will be invoked right before the
118+ * associated effect re-runs.
119+ *
120+ * @param cleanupFn - The callback function to attach to the effect's cleanup.
121+ */
108122export function onEffectCleanup ( cleanupFn : ( ) => void ) {
109123 if ( activeEffect ) {
110124 const cleanups =
111125 cleanupMap . get ( activeEffect ) ||
112126 cleanupMap . set ( activeEffect , [ ] ) . get ( activeEffect ) !
113127 cleanups . push ( cleanupFn )
128+ } else if ( __DEV__ ) {
129+ warn (
130+ `onEffectCleanup() was called when there was no active effect` +
131+ ` to associate with.` ,
132+ )
114133 }
115134}
116135
You can’t perform that action at this time.
0 commit comments