Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patchProp函数为元素添加监听函数时是不是要先用createInvoker函数包装监听函数? #96

Open
dizaowudishenhua opened this issue Dec 11, 2022 · 0 comments

Comments

@dizaowudishenhua
Copy link

dizaowudishenhua commented Dec 11, 2022

function patchProp(el, key, preValue, nextValue) {
if (isOn(key)) {
const invokers = el._vei || (el._vei = {});
const existingInvoker = invokers[key];
if (nextValue && existingInvoker) {
existingInvoker.value = nextValue; //这个invoker是一个函数,直接修改function.value是不是有点问题?我没有找到类似写法
} else {
const eventName = (key).slice(2).toLowerCase();
if (nextValue) {
const invoker = (invokers[key] = nextValue); //没用createInvoker包装函数去包装,所以invoker是一个函数
el .addEventListener(eventName, invoker);
} else {
el.removeEventListener(eventName, existingInvoker);
invokers[key] = undefined;
}
}
} else {
if (nextValue === null || nextValue === "") {
el.removeAttribute(key);
} else {
el.setAttribute(key, nextValue);
}
}
}

@dizaowudishenhua dizaowudishenhua changed the title patchProp函数里为元素添加监听函数是不是少了一个createInvoker包装函数? patchProp函数为元素添加监听函数时是不是要先用createInvoker函数包装监听函数? Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant