Преглед на файлове

feat(reactivity): add failSilently argument for onScopeDispose

Evan You преди 2 години
родител
ревизия
9a936aaec4
променени са 1 файла, в които са добавени 2 реда и са изтрити 2 реда
  1. 2 2
      packages/reactivity/src/effectScope.ts

+ 2 - 2
packages/reactivity/src/effectScope.ts

@@ -136,10 +136,10 @@ export function getCurrentScope() {
  * @param fn - The callback function to attach to the scope's cleanup.
  * @param fn - The callback function to attach to the scope's cleanup.
  * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
  * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
  */
  */
-export function onScopeDispose(fn: () => void) {
+export function onScopeDispose(fn: () => void, failSilently = false) {
   if (activeEffectScope) {
   if (activeEffectScope) {
     activeEffectScope.cleanups.push(fn)
     activeEffectScope.cleanups.push(fn)
-  } else if (__DEV__) {
+  } else if (__DEV__ && !failSilently) {
     warn(
     warn(
       `onScopeDispose() is called when there is no active effect scope` +
       `onScopeDispose() is called when there is no active effect scope` +
         ` to be associated with.`,
         ` to be associated with.`,