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

Support for events? #16

Open
rolfen opened this issue Sep 9, 2017 · 0 comments
Open

Support for events? #16

rolfen opened this issue Sep 9, 2017 · 0 comments

Comments

@rolfen
Copy link

rolfen commented Sep 9, 2017

I would like to use your library, yet I do not see any code dealing with events.

I could register events on the container, however I believe that it is preferable to have the option of registering events on all elements.

I am sure there are different strategies to deal with events.

Maybe the simplest and most flexible option is to have an additional optional parameter on the hyperscript function (el()), it would be a function, and this function gets called every time the HTML element corresponding to that vnode gets modified, or created.

Basically like "lifecycle events" for HTML elements which are managed by SVD.

So for example:

el('a', {'href':'#something'}, null, function(element, lifecycleEvent){
   if(lifecycleEvent == 'created') {
      // the HTML element for this vdom node was just created, add event listeners
      element.addEventListener('click', function(){
          // attach an event listener
      });
   }
});

We can then build on this functionality to do more complicated things if needed.

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