yoshuawuyts / microcomponent

Smol event based component library
MIT License
35 stars 11 forks source link

Bigger example _and_ fix render logic #17

Closed juliangruber closed 7 years ago

juliangruber commented 7 years ago
screen shot 2017-05-23 at 09 50 25

so far everything works fine!

juliangruber commented 7 years ago

next i want to add reordering

juliangruber commented 7 years ago

ok, this triggers a bug now: when you move down the first element, the placeholder element will be rendered

juliangruber commented 7 years ago

this is a comparison of the dom: https://gist.github.com/juliangruber/9f76bea837968fd4d27560eeaf56c067

juliangruber commented 7 years ago

It's a bit tricky to explain what was going on here, but I'll try my best:

Before, we were overwriting this._render in this module. Nanocomponent calls to this._render() and then afterwards applies the this._ID logic. That means however, that the new tree that is being morphed in this module, doesn't have the ID yet! => nanomorph thinks it's different nodes

I therefore changed it to be the other way around. In this module, we set this._render to the handler function passed to .on('render', handler), and then override this.render with our morphing logic. So before it was nanocomponent calling microcomponent's render function, now it's microcomponent calling nanocomponent's render function. Which is the right way around.

The example now works 100% for me, as long as you update your local nanocomponent to this PR: https://github.com/yoshuawuyts/nanocomponent/pull/33

juliangruber commented 7 years ago

3.1.4