@slim-lang/core 1.2.17 → 1.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slim-lang/core",
3
- "version": "1.2.17",
3
+ "version": "1.2.18",
4
4
  "description": "Slim extends JavaScript with runtime types, structs, operators, and components, compiling to plain Javascript",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -223,7 +223,11 @@ class Server {
223
223
 
224
224
  if (options && "hydrate" in options) {
225
225
  const props = { dev: isDev, params, url: req.url }
226
- const rendered = await renderToStringAsync(() => render(props))
226
+ let initialStore = null
227
+ if ("load" in options && typeof options.load == "function") {
228
+ initialStore = await options.load(props)
229
+ }
230
+ const rendered = await renderToStringAsync(() => render(props), { store: initialStore })
227
231
  const data = JSON.stringify(props).replace(/</g, "\\u003c")
228
232
  const bootstrap = this.#hydrateBootstrap(options.hydrate)
229
233
  html = `<div id="slim-root">${rendered.html}</div>` + rendered.script +
@@ -621,9 +621,9 @@ export function renderToString(render) {
621
621
  }
622
622
  }
623
623
 
624
- export async function renderToStringAsync(render, { passes = 5 } = {}) {
624
+ export async function renderToStringAsync(render, { passes = 5, store: initialStore } = {}) {
625
625
  const data = { results: [], pending: [], index: 0 }
626
- const store = {}
626
+ const store = initialStore && typeof initialStore === "object" ? initialStore : {}
627
627
  setServerStore(store)
628
628
  try {
629
629
  for (let pass = 1; ; pass++) {