File tree 1 file changed +19
-0
lines changed 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
105
105
const cleanupMap : WeakMap < ReactiveEffect , ( ( ) => void ) [ ] > = new WeakMap ( )
106
106
let activeEffect : ReactiveEffect | undefined = undefined
107
107
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
+ */
108
122
export function onEffectCleanup ( cleanupFn : ( ) => void ) {
109
123
if ( activeEffect ) {
110
124
const cleanups =
111
125
cleanupMap . get ( activeEffect ) ||
112
126
cleanupMap . set ( activeEffect , [ ] ) . get ( activeEffect ) !
113
127
cleanups . push ( cleanupFn )
128
+ } else if ( __DEV__ ) {
129
+ warn (
130
+ `onEffectCleanup() was called when there was no active effect` +
131
+ ` to associate with.` ,
132
+ )
114
133
}
115
134
}
116
135
You can’t perform that action at this time.
0 commit comments