funkia / turbine

Purely functional frontend framework for building web applications
MIT License
684 stars 27 forks source link

Simple server side rendering #26

Open paldepind opened 7 years ago

paldepind commented 7 years ago

With a way to stringify a component it would be possible to support simple server side rendering.

The API could consist of componentToString and serveComponent. The first would turn a component into a string and the second would return a NodeJS compatible endpoint function.

Example.

app.get("/app", serveComponent("index.html", "body", myComponent));

This would offer a really simple way of getting many of the benefits from server-side rendering with very little effort from end-users.

limemloh commented 7 years ago

I imagine that we can use something like JSDOM to run the component in NodeJS and pre-generate the DOM.

paldepind commented 7 years ago

@trusktr

That would be awesome to do with Turbine. Maybe we can just run turbine stuff in jsdom, and get the output?

Maybe there could be a way to make Turbine output strings instead of actual DOM elements?

If possible I think turning Components into strings directly is best. If this is something that interests you I can put a simple proof of concept together to illustrate how I imagine it can be implemented.

What do you think about the API I show in the post above?

trusktr commented 6 years ago

@paldepind I suppose that works. I'm also looking at Vue+Nuxt.js, which abstracts that part away.

trusktr commented 6 years ago

They do it very very declaratively. But so do you!! I think the functional-to-HTML approach you have is nice.