enhance-dev / enhance-ssr

Server side render for custom elements.
143 stars 9 forks source link

Is it possible to add `initialState` after invoking enhance-ssr? #25

Closed tbeseda closed 2 years ago

tbeseda commented 2 years ago

Let's say I have a function that returns some HTML rendered by Enhance SSR

function (req) {
  const html = enhance({
    /* ... a lot of config for
      elements,
      transforms,
      and state. */
  })

  // a bunch of logic based on req

  return html`<my-page></my-page>`
}

Can I change initialState on my html method before returning a result?
I could just create the html method later in my function when the initialState is settled, but I may want to actually return early to avoid extra computation and branching logic.

Basically, everything is the same for each invocation of my function, except the state I want to pass to Enhance.

This could also be nice if I want to create html outside of the main function and potentially reuse it in subsequent requests to that function -- thinking about a "warm" Lambda.

kristoferjoseph commented 2 years ago

No this is just for initial render. In the client you will be able to subscribe to a store and re-render to updates.