-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime): Basic implementation of the patchEvent() function
- Loading branch information
Showing
4 changed files
with
80 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,48 @@ | ||
import { EMPTY_OBJ } from '@vue/shared' | ||
import { INSVElement } from '../nodes' | ||
import { ComponentInternalInstance } from '@vue/runtime-core' | ||
|
||
export function patchEvent( | ||
el: INSVElement, | ||
name: string, | ||
prevValue: any, | ||
nextValue: any, | ||
instance: ComponentInternalInstance | null = null | ||
nextValue: any | ||
) { | ||
// todo implement patchEvent | ||
const prevOptions = prevValue && 'options' in prevValue && prevValue.options | ||
const nextOptions = nextValue && 'options' in nextValue && nextValue.options | ||
const invoker = prevValue && prevValue.invoker | ||
const value = | ||
nextValue && 'handler' in nextValue ? nextValue.handler : nextValue | ||
|
||
if (prevOptions || nextOptions) { | ||
const prev = prevOptions || EMPTY_OBJ | ||
const next = nextOptions || EMPTY_OBJ | ||
if ( | ||
prev.capture !== next.capture || | ||
prev.passive !== next.passive || | ||
prev.once !== next.once | ||
) { | ||
if (invoker) { | ||
el.removeEventListener(name, invoker) | ||
} | ||
if (nextValue && value) { | ||
const invoker = value | ||
nextValue.invoker = invoker | ||
// TODO: use nextOptions here for supporting event options | ||
el.addEventListener(name, invoker) | ||
} | ||
return | ||
} | ||
} | ||
|
||
if (nextValue && value) { | ||
if (invoker) { | ||
;(prevValue as any).invoker = null | ||
invoker.value = value | ||
nextValue.invoker = invoker | ||
} else { | ||
el.addEventListener(name, value) | ||
} | ||
} else if (invoker) { | ||
el.removeEventListener(name, invoker) | ||
} | ||
} |
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