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

Event listener names are duplicated #2

Open
alexchandel opened this issue Mar 27, 2015 · 1 comment
Open

Event listener names are duplicated #2

alexchandel opened this issue Mar 27, 2015 · 1 comment

Comments

@alexchandel
Copy link

Do these listeners really need to be hooks? Maybe just set the on* stuff.

What exactly does this mean; why are there effectively two "click"s in your vnodes? I notice the String is passed to addEventListener inside the HookFn, but the record name doesn't appear to affect anything.

vnode "div" { click: hook "click" handler } [ ]
@fluffynukeit
Copy link
Owner

With virtual-dom, you can make your own custom vnode properties and name them whatever you want as long as their value is a "hook". The hook defines what happens when such a custom property is added or removed. So you're right, the property name "click" doesn't affect anything. I could have called it "banzai" or "orange" or whatever. But I need to call it something so that virtual-dom can compare it between renders to the previous value and do an update if needed. I happened to call it click because it is a hook that sets up a click handler.

The comment about needing to be hooks is implying that this is a dumb way to do it. You don't need hooks to set up click handlers because you can just use the "onclick" property as long as the value you provide to onclick has the correct form. I was experimenting with vdom and trying things out, which is why the hook method is still in there with a comment suggesting a better way to do it.

You might also want to check out puzzler2, which uses the onclick, etc, directly. That implementation has its own set of problems, but I think is overall cleaner in terms of the view.

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

2 participants