snabbdom / snabbdom-to-html

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

Support `thunks` #3

Closed acstll closed 8 years ago

acstll commented 8 years ago

…should be simple.

paldepind commented 8 years ago

What about using a dummy thunk helper server side? Something like this:

function thunk(name, fn) {
  var i, args = [];
  for (i = 2; i < arguments.length; ++i) {
    args[i - 2] = arguments[i];
  }
  return fn.apply(null, args);
}

That pretty much makes thunk a no-op.

acstll commented 8 years ago

I had this in mind, which should make it seamless:

https://github.com/acstll/snabbdom-to-html/blob/thunks/init.js#L26-L28

I also added a test https://github.com/acstll/snabbdom-to-html/blob/thunks/test/index.js#L217

What do you think? could there be any edge cases? I've never used thunks myself. :)

acstll commented 8 years ago

@paldepind I just realized I need to call apply on those arguments! Will fix…

acstll commented 8 years ago

Added in 2.1.0