riot / ssr

Riot.js node Server Side Rendering
MIT License
32 stars 8 forks source link

SSR should support async onBeforeMount #13

Closed cybervaldez closed 4 years ago

cybervaldez commented 4 years ago

It would be a great idea to support asynchronous mounts in SSR, since a lot of our data population logic are promise-based (external fetching)

async onBeforeMount(){
   this.data = await populate()
}

it just makes more sense this way with riot's one way dataflow(parent to child), compare to what we have right now: app -- child --- grandchild

say if we want to populate grandchild, we need to pass the data around from the root and pass to each child component attributes until it reaches grandchild which just isn't elegant.

let grandchild_data = await populate()
let html = render('app', App, { ssr : true, url : "/browse", { data : { grandchild : grandchild_data }}});
cybervaldez commented 4 years ago

Changed the title since onBeforeMount is where we usually set initial property state