Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

getComponent support function return a Promise #51

Closed
baoti opened this issue Feb 26, 2017 · 10 comments
Closed

getComponent support function return a Promise #51

baoti opened this issue Feb 26, 2017 · 10 comments

Comments

@baoti
Copy link

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

baoti commented Feb 27, 2017

@ljharb Yes.

@ljharb
Copy link
Collaborator

ljharb commented Feb 27, 2017

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

@baoti
Copy link
Author

baoti commented Feb 27, 2017

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

@baoti
Copy link
Author

baoti commented Feb 27, 2017

context.html = renderFn(context.props);

context.html got a Promise, not a string.

@ljharb
Copy link
Collaborator

ljharb commented Feb 27, 2017

Gotcha; so you'd need

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

Seems doable/reasonable to me.

@marconi1992
Copy link
Contributor

@baoti
Copy link
Author

baoti commented Feb 27, 2019

It's already supported since [2.1.1] - 2017-06-15, commit.

@baoti baoti closed this as completed Feb 27, 2019
@baoti
Copy link
Author

baoti commented Feb 27, 2019

@marconi1992 Thanks, It works.

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

No branches or pull requests

3 participants