choojs / nanohtml

:dragon: HTML template strings for the Browser with support for Server Side Rendering in Node.
MIT License
687 stars 57 forks source link

update(old, new) #9

Closed nrn closed 8 years ago

nrn commented 8 years ago

Any thoughts on trasitioning update to being a function that takes the old element as it's first argument, instead of adding a property to the element? It feels like it would fit better with my expectations approaching the interface. And it seems like you could then update elements not created by bel, which would be nice.

shama commented 8 years ago

That could be done by using morphdom or diffhtml directly:

var bel = require('bel')
var element = bel`<div>hello</div>`

// ... later ...

var morphdom = require('morphdom')
var newelement = bel`<div>changed</div>`
morphdom(element, newelement)

But I have it tied to the element to encourage data down, actions up. I'd be worried about elements getting updated by multiple sources and conflicting with each other.

nrn commented 8 years ago

It is surprising to me for real dom elements to have extra methods on them, but it totally makes sense why you're going that way!

shama commented 8 years ago

I considered replacing .outerHTML with a setter to the update function but wasn't sure if that was a good idea or not. See #6

Maybe better wording would be, "almost pure elements." :)