refactor: extract remove util
This commit is contained in:
parent
fd031490fb
commit
583f9468fa
@ -14,7 +14,8 @@ import {
|
|||||||
isFunction,
|
isFunction,
|
||||||
isString,
|
isString,
|
||||||
hasChanged,
|
hasChanged,
|
||||||
NOOP
|
NOOP,
|
||||||
|
remove
|
||||||
} from '@vue/shared'
|
} from '@vue/shared'
|
||||||
import {
|
import {
|
||||||
currentInstance,
|
currentInstance,
|
||||||
@ -264,11 +265,7 @@ function doWatch(
|
|||||||
return () => {
|
return () => {
|
||||||
stop(runner)
|
stop(runner)
|
||||||
if (instance) {
|
if (instance) {
|
||||||
const effects = instance.effects!
|
remove(instance.effects!, runner)
|
||||||
const index = effects.indexOf(runner)
|
|
||||||
if (index > -1) {
|
|
||||||
effects.splice(index, 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
import { VNode, cloneVNode, isVNode, VNodeProps } from '../vnode'
|
import { VNode, cloneVNode, isVNode, VNodeProps } from '../vnode'
|
||||||
import { warn } from '../warning'
|
import { warn } from '../warning'
|
||||||
import { onBeforeUnmount, injectHook, onUnmounted } from '../apiLifecycle'
|
import { onBeforeUnmount, injectHook, onUnmounted } from '../apiLifecycle'
|
||||||
import { isString, isArray, ShapeFlags } from '@vue/shared'
|
import { isString, isArray, ShapeFlags, remove } from '@vue/shared'
|
||||||
import { watch } from '../apiWatch'
|
import { watch } from '../apiWatch'
|
||||||
import { SuspenseBoundary } from './Suspense'
|
import { SuspenseBoundary } from './Suspense'
|
||||||
import {
|
import {
|
||||||
@ -297,7 +297,6 @@ function injectToKeepAliveRoot(
|
|||||||
) {
|
) {
|
||||||
injectHook(type, hook, keepAliveRoot, true /* prepend */)
|
injectHook(type, hook, keepAliveRoot, true /* prepend */)
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
const hooks = keepAliveRoot[type]!
|
remove(keepAliveRoot[type]!, hook)
|
||||||
hooks.splice(hooks.indexOf(hook), 1)
|
|
||||||
}, target)
|
}, target)
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,13 @@ export const extend = <T extends object, U extends object>(
|
|||||||
return a as any
|
return a as any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const remove = <T>(arr: T[], el: T) => {
|
||||||
|
const i = arr.indexOf(el)
|
||||||
|
if (i > -1) {
|
||||||
|
arr.splice(i, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||||
export const hasOwn = (
|
export const hasOwn = (
|
||||||
val: object,
|
val: object,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user