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

getComponent support function return a Promise #51

Open
baoti opened this Issue Feb 26, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@baoti

baoti commented Feb 26, 2017

I am working on vue bindings for Hypernova, but vue-server-renderer renderer pass html by callback:

const Vue = require('vue')
 
const renderer = require('vue-server-renderer').createRenderer()
 
const vm = new Vue({
  render (h) {
    return h('div', 'hello')
  }
})

renderer.renderToString(vm, (err, html) => {
  console.log(html) // -> <div server-rendered="true">hello</div> 
})

So, I'd like getComponent support a function which return a Promise, just like props => Promise.resole(html).

@baoti

This comment has been minimized.

baoti commented Feb 26, 2017

Vue bindings for server like this:

export const renderVue = (name, component) => hypernova({
  server() {
    return (props) => {
      const vm = new component({ propsData: props });
      return new Promise((resolve, reject) => {
        renderer.renderToString(vm, (err, html) => {
          if (err) {
            reject(err);
          } else {
            resolve(serialize(name, html, props));
          }
        });
      });
    };
  },
}
@ljharb

This comment has been minimized.

Member

ljharb commented Feb 26, 2017

I'm not sure I understand - are you saying that the vue server renderer does not synchronously produce a string?

@baoti

This comment has been minimized.

baoti commented Feb 27, 2017

@ljharb Yes.

@ljharb

This comment has been minimized.

Member

ljharb commented Feb 27, 2017

According to the code, getComponent's return value is already passed into Promise.resolve.

@baoti

This comment has been minimized.

baoti commented Feb 27, 2017

getComponent's return value is a function, but renderFn(context.props)'s return value is a Promise.

@baoti

This comment has been minimized.

baoti commented Feb 27, 2017

context.html = renderFn(context.props);

context.html got a Promise, not a string.

@ljharb

This comment has been minimized.

Member

ljharb commented Feb 27, 2017

Gotcha; so you'd need

context.html = renderFn(context.props);
changed.

Seems doable/reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment