snabbdom / snabbdom-to-html

Render Snabbdom Vnode’s to HTML strings
94 stars 21 forks source link

Issues when vnode.data is undefined #5

Closed TylorS closed 8 years ago

TylorS commented 8 years ago

Hello @acstll easy fixes here :+1:

Overview

When trying to convert snabbdom vnodes to html and vnode.data is undefined 3 separate errors occur.

  1. https://github.com/acstll/snabbdom-to-html/blob/master/modules/attributes.js#L22
    • First complains that there is no props on undefined
  2. https://github.com/acstll/snabbdom-to-html/blob/master/modules/style.js#L11
    • Next complains that there is no style on undefined
  3. https://github.com/acstll/snabbdom-to-html/blob/master/init.js#L25
    • Lastly, complains that there is no ns on undefined

      Possible Fix

// easy fix
if (!vnode.data) {
  vnode.data = {}
}

Or more checks can be done to ensure other things are not being missed.

acstll commented 8 years ago

hey @TylorS

The fix is coming today. :+1:

I wonder if you're creating vnodes manually, using the h function always yields an empty object for data.

TylorS commented 8 years ago

I generally wrap up h() using hyperscript-helpers Maybe thats my issue, but I don't believe it should be.

TylorS commented 8 years ago

It could be some of the stuff I do in motorcycle as well

acstll commented 8 years ago

@TylorS no worries. I'll add the protection which is nice to have anyways…

TylorS commented 8 years ago

:+1: I appreciate it @acstll

acstll commented 8 years ago

Glad to help! 2.0.1 has the fix.

TylorS commented 8 years ago

Super speedy! Thanks again.

Not sure if it's something you're interested in, but I whipped up this little library you may be interested in https://github.com/TylorS/snabbdom-selector. It basically just takes a snabbdom vTree and parses it for css-selectors. I'm attempting to use it for Motorcycle, but I'm not sure if it would be handy for you or others..

acstll commented 8 years ago

No problem. :+1:

Thanks for sharing. I'll let you know if I find a use for it. One thing I noticed is that it might be a good idea to abstract the parseSelector function into its own module so we stop reproducing it every time :smile: What do you think?

TylorS commented 8 years ago

Yeah, that probably couldn't hurt I really just borrowed yours, as it was much better than mine :wink:

acstll commented 8 years ago

I'll do it then… haha I lifted it from virtual-dom myself as you propably noticed :smile:

TylorS commented 8 years ago

Open-source FTW! :fire: