-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3e07b4
commit 818ccb6
Showing
9 changed files
with
98 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
import { invokeArrayFns } from '@vue/shared' | ||
import { NOOP, invokeArrayFns } from '@vue/shared' | ||
import type { VaporLifecycleHooks } from './enums' | ||
import { type ComponentInternalInstance, setCurrentInstance } from './component' | ||
import { queuePostFlushCb } from './scheduler' | ||
import { type DirectiveHookName, invokeDirectiveHook } from './directives' | ||
import { queuePostFlushCb } from './scheduler' | ||
|
||
export function invokeLifecycle( | ||
instance: ComponentInternalInstance, | ||
lifecycle: VaporLifecycleHooks, | ||
directive: DirectiveHookName, | ||
cb?: (instance: ComponentInternalInstance) => void, | ||
cb?: () => void, | ||
post?: boolean, | ||
) { | ||
invokeArrayFns(post ? [invokeSub, invokeCurrent] : [invokeCurrent, invokeSub]) | ||
const fn = scheduleLifecycleHooks(instance, lifecycle, directive, cb, post) | ||
return post ? queuePostFlushCb(fn) : fn() | ||
} | ||
|
||
function invokeCurrent() { | ||
cb && cb(instance) | ||
const hooks = instance[lifecycle] | ||
if (hooks) { | ||
const fn = () => { | ||
const reset = setCurrentInstance(instance) | ||
instance.scope.run(() => invokeArrayFns(hooks)) | ||
reset() | ||
} | ||
post ? queuePostFlushCb(fn) : fn() | ||
} | ||
export function scheduleLifecycleHooks( | ||
instance: ComponentInternalInstance, | ||
lifecycle: VaporLifecycleHooks, | ||
directive: DirectiveHookName, | ||
cb = NOOP, | ||
reverse?: boolean, | ||
) { | ||
const hooks = reverse | ||
? [cb, callDirHooks, callLifecycleHooks] | ||
: [callLifecycleHooks, callDirHooks, cb] | ||
|
||
return () => invokeArrayFns(hooks) | ||
|
||
function callDirHooks() { | ||
invokeDirectiveHook(instance, directive, instance.scope) | ||
} | ||
|
||
function invokeSub() { | ||
instance.comps.forEach(comp => | ||
invokeLifecycle(comp, lifecycle, directive, cb, post), | ||
) | ||
function callLifecycleHooks() { | ||
// lifecycle hooks may be mounted halfway. | ||
const lifecycleHooks = instance[lifecycle] | ||
if (lifecycleHooks && lifecycleHooks.length) { | ||
const reset = setCurrentInstance(instance) | ||
instance.scope.run(() => invokeArrayFns(lifecycleHooks)) | ||
reset() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters