ericponto / html2IDOM

Convert a string of HTML into Incremental DOM
17 stars 3 forks source link

Event delegation #1

Open LucaColonnello opened 9 years ago

LucaColonnello commented 9 years ago

Great projects!! Possibility to handle events?

If you want I could help and contribute!

ericponto commented 9 years ago

I think Incremental DOM handles passing events via onclick type attributes. So we should be able to make something work. If you'd like to take a shot and submit a PR that would be great. I will look at it some too.

LucaColonnello commented 9 years ago

Ok @ericponto, let me do some considerations:

  1. we have to make the library able to share a context for the parsing in which we could put all the handlers and the data that the template system has to parse and use (a template system could be done with es6 templating strings, take a look at this RequireBIN http://requirebin.com/?gist=491f3d97786ed2e59442).
  2. I think that the parser couldn't be only one in order to manage contexts
  3. we have to build probably a system for attributes managment in order to manage all that non-native event like onTouch or onSwipe using third party library, considering how incremental dom applying events, how can we work with events listeners only when a determinate event has to be inserted or removed.

Could make sense for you?

Obviously if we don't wanna give all of these responsibilities to this library, we have to make developers able to create own libs using this one, but making it possible to solve all of these issues...

For example we can implement some callback for attribute changes (checking Incremental DOM possibilities) and giving a context to the parser where converts attributes values to handlers (as event callback) or other operations..

ericponto commented 9 years ago

My though is that you could use any string based template system, so don't want to limit it to ES6 template strings.

I think the html parser could catch all the attributes that start with "on" and then we could do anything we want with them. And yeah, for delegation we probably need to keep track of all the events somehow, then compare when patchHTML is called.

LucaColonnello commented 9 years ago

Yeah, but the problem is that by now tha parser doesn't know the context that contains all the event handlers.. Could we make this context shared with the parser? Probably we have to create multiple parser instances or pass to it the context during parse phase...