Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snabbdom Support #36

Open
jessehattabaugh opened this issue Oct 12, 2016 · 8 comments
Open

Snabbdom Support #36

jessehattabaugh opened this issue Oct 12, 2016 · 8 comments

Comments

@jessehattabaugh
Copy link

jessehattabaugh commented Oct 12, 2016

Snabbdom uses a hyper-script-like function to build it's vdoms, but it's second argument is different. Instead of attributes it's properties are used by various "modules";

h('div', {
  props: {title: someString}, // snabbdom/modules/props
  classes: {selected: isSelected}, // snabbdom/modules/class
  on: {click: doSomething}, // snabbdom/modules/eventlisteners
  style: {color: someColor} // snabbdom/modules/style
}, ['children'])

The snabbdom-jsx module handles this using prefixed attributes in JSX:

<div 
  title={someString} 
  class-selected={isSelected} 
  on-click={doSomething} 
  style: {({color: someColor})}
>
  children
</div>

Would it be feasible for hyperx to do this as well?

@fiatjaf
Copy link

fiatjaf commented Oct 29, 2016

You could create a wrapper around snabbdom's h and pass it to hyperx, so it could recognize prefixed attributes, or make intelligent choices.

@jorgebucaran
Copy link

Maybe this can help https://www.npmjs.com/package/hyperx-to-snabbdom.

@niksy
Copy link

niksy commented Dec 30, 2016

Can this be supported inside hyperx, maybe through special option like concat? Using another module seems like unecessary overhead, and hyperx could be useful for render functions in Vue out od the box (Vue uses snabbdom as vdom library).

@jorgebucaran
Copy link

jorgebucaran commented Dec 31, 2016

@niksy How should hyperx deal with snabbdom unique idioms, like hooks?

@jamen
Copy link
Contributor

jamen commented Jan 29, 2017

Ohh, interesting I've found this after creating a module.

I made snabby which is more like yo-yo.

@jbucaran for handling hooks inside this module, I plan to use a snabby.hooks function, e.g.:

snabby.hook(vnode, { ...handles })
// Or
snabby.hook(vnode, handle, fn)

Although I haven't implemented this yet, or on that note, even written tests for anything... It is pretty experimental

Looking for people to collaborate on it, if anyone is interested.

@jorgebucaran
Copy link

@jamen Here is what I ended up with. Essentially:

} else if ("data-hook-" === key.substr(0, 10)) {
    data.hook[key.substr(10)] = value
}

Good luck with Snabby!

@jamen
Copy link
Contributor

jamen commented Jan 30, 2017

@jbucaran That structure you've got makes sense after I've experimented more. I'm probably going to have to do something similar. So let me know if you want me to add you as collaborator on Snabby.

@jamen
Copy link
Contributor

jamen commented Jan 31, 2017

An update on this, I've made snabby support hooks and various other modules, by using an s-* prefix (similar to v-* in vue).

Example:

snabby`
  <div s-hook:destroy=${fn}>
  </div>
`

// Using `eventlisteners`:
snabby`
  <div s-on:click=${...}>
  </div>
`

Open to suggestion on how to make this look more nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants