TimBeyer / html-to-vdom

Converts an HTML string into a virtual DOM
172 stars 41 forks source link

Sync method #1

Closed gsf closed 10 years ago

gsf commented 10 years ago

This is great but I could really use a sync version. Any plans to do so or should I create a separate project?

TimBeyer commented 10 years ago

Since I am using https://github.com/tautologistics/node-htmlparser which only provides an async API, I am afraid there will not be a sync version.
What do you need to do that requires a sync version if I may ask?

gsf commented 10 years ago

Thanks for the response. I thought sync might be tricky with htmlparser.

I have items with certain fields (such as "description") in HTML that need to be rendered. With vdom-virtualize I'm able to do the following:

var h = require('virtual-hyperscript')
var fromHTML = require('vdom-virtualize').fromHTML

module.exports = function (item) {
  return h('.item#' + item.id, [
    h('h2', [
      h('span.item-main', item.main),
      ' ',
      h('span.item-type', '(' + item.type + ')')
    ]),
    fromHTML('<div class="description">'+item.description+'</div>')
  ])
}

I'll see if server-side parsing could find its way into vdom-virtualize with parse5.

TimBeyer commented 10 years ago

I've had good experiences with making all view rendering asynchronous in our projects.
Once you use promises, it's very easy to collect those and wait for their completion if you need to for example render multiple views before doing something else.

Asynchronicity is viral, meaning that if you need one single step in your rendering process to be async, it will spread to everything that touches rendering. Since so many 3rd party libraries use an asynchronous interface, the decision to go async everywhere in the rendering process has definitely paid off for us.

It allowed us for example to integrate a virtual dom into our views in a very short time.

TimBeyer commented 9 years ago

@gsf The API has now been changed to sync. I hope it's not too late to be useful for you.

gsf commented 9 years ago

Thanks! Good to know.