airbnb / hypernova-node

node.js client for Hypernova
https://github.com/airbnb/hypernova
MIT License
73 stars 26 forks source link

Guidance needed: how to call multiple versions of the same component? #14

Open magicmark opened 7 years ago

magicmark commented 7 years ago

Hi,

Consider the following call:

const renderer = new Renderer({
    url: 'http://localhost:8080/batch',
});

renderer.render({
    Sheep: {},
    Cow: {"food": "grass"},
    Cow: {"food": "egg salad sandwiches"},
}).then(html => {
    console.log(html);
});

(Clearly, this won't work because the first Cow gets overridden.)

I'm looking to be able to batch requests for multiple components in one http call. I'd also want to specify individual keys per component, and also get a separated json response with the rendered markup.

Querying the Hypernova server directly through the API allows me to do exactly this, and the output looks the same as far as I can tell.

Apart from missing out on the plugins and their lifecycle methods, is there anything else I'd be missing by not using this library that I should be aware of?

(I've been toying with a renderRaw method to just pass in a Jobs object, but this may not be necessary?)

Thanks so much!

wingleung commented 5 years ago

Not sure if this is still relevant to you but maybe the batch calls could be handled by a service in front of hypernova. So you would call that service and that service would do the batching for you so you still would fetch one endpoint for multiple components. That dedicated component service could also handle fetching data or figure out what properties to send to each component. More info on how we did this -> https://medium.com/vrt-digital-studio/server-side-rendering-react-components-as-a-service-9d6b887cb02a