choojs / nanomorph

🚅 - Hyper fast diffing algorithm for real DOM nodes
MIT License
725 stars 57 forks source link

Add support for `data-same-node` attribute #92

Closed brechtcs closed 6 years ago

brechtcs commented 6 years ago

This PR makes it possible to control isSameNode behaviour through a data-same-node attribute in the element markup. I think this results in a slightly more idiomatic syntax when using this in choo, for example:

function view (state, emit) {
    return html`<nav data-same-node=${changeNav(state.navigation)}>
        <ul>${state.navigation.current.map(navItem)}</ul>
    </nav>`
}

function changeNav (navigation) {
    return navigation.current.length !== navigation.prev.length
}

If you're interested in merging this, I'll add some documentation to the "Caching DOM elements" section.

yoshuawuyts commented 6 years ago

Hmmmmm, I've got feelings about this. So far in Choo we've tried real hard to only use DOM builtins. For everything. The nanommorph library could in theory be used as the basis of a web spec. So I'm a little reluctant to add non-standard attributes, as they kinda go against that. Does that make sense?

soyuka commented 6 years ago

IMO the isSameNode method is sufficient.

yoshuawuyts commented 6 years ago

ping @brechtpm; you okay if we would close this? Want to make sure you won't be stuck; if there's some functionality we aren't covering, we probably should take care of it.

brechtcs commented 6 years ago

Nope I'm not stuck. At the moment I'm just experimenting with some other ways to implement server-side rendering and rehydration, and I anticipate something like this could become useful at some point.

I'll try open a new issue when I have a more concrete use case, and then we move on from there.