revojs 0.0.84 → 0.0.85
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/dist/index.js +24 -6
- package/dist/runtime/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -441,8 +441,12 @@ async function $fetch(scope, input, options) {
|
|
|
441
441
|
function useState(scope, name, value) {
|
|
442
442
|
const state = createState(value);
|
|
443
443
|
if (isClient()) {
|
|
444
|
-
|
|
445
|
-
|
|
444
|
+
if (STATES === void 0) {
|
|
445
|
+
const element = document.getElementById("STATES");
|
|
446
|
+
STATES = element?.textContent ? JSON.parse(element.textContent) : {};
|
|
447
|
+
}
|
|
448
|
+
state.value = STATES[name];
|
|
449
|
+
createCompute(scope, () => STATES && (STATES[name] = state.value));
|
|
446
450
|
}
|
|
447
451
|
if (isServer()) {
|
|
448
452
|
const { states } = useRuntime(scope);
|
|
@@ -458,7 +462,7 @@ function useAsync(scope, name, invoke, options) {
|
|
|
458
462
|
isLoading.value = true;
|
|
459
463
|
try {
|
|
460
464
|
const result = await invoke();
|
|
461
|
-
if (options?.viewTransition) await startViewTransition(options.viewTransition, () => state.value = result);
|
|
465
|
+
if (JSON.stringify(state.value ?? {}) !== JSON.stringify(result)) if (options?.viewTransition) await startViewTransition(options.viewTransition, () => state.value = result);
|
|
462
466
|
else state.value = result;
|
|
463
467
|
} catch (error) {
|
|
464
468
|
options?.catch?.(error);
|
|
@@ -488,8 +492,21 @@ async function createRuntime() {
|
|
|
488
492
|
const route = routes[path];
|
|
489
493
|
if (isRoute(route)) return route.fetch(scope);
|
|
490
494
|
const { states } = useRuntime(scope);
|
|
491
|
-
const content = await renderToString(scope, await import("#virtual/client").then((module) => module.client), { head: { children: ["<!--
|
|
492
|
-
|
|
495
|
+
const content = await renderToString(scope, await import("#virtual/client").then((module) => module.client), { head: { children: ["<!--STATES-->"] } });
|
|
496
|
+
const entries = Object.entries(states).reduce((states$1, [name$1, state]) => {
|
|
497
|
+
return {
|
|
498
|
+
...states$1,
|
|
499
|
+
[name$1]: state.value
|
|
500
|
+
};
|
|
501
|
+
}, {});
|
|
502
|
+
return sendHtml(scope, content.replace("<!--STATES-->", await renderToString(scope, {
|
|
503
|
+
tag: "script",
|
|
504
|
+
attributes: {
|
|
505
|
+
id: "STATES",
|
|
506
|
+
type: "application/json"
|
|
507
|
+
},
|
|
508
|
+
children: [JSON.stringify(entries)]
|
|
509
|
+
})));
|
|
493
510
|
} }));
|
|
494
511
|
}
|
|
495
512
|
const assets = await import("#virtual/assets").then((module) => module.default);
|
|
@@ -532,6 +549,7 @@ async function createRuntime() {
|
|
|
532
549
|
}
|
|
533
550
|
};
|
|
534
551
|
}
|
|
552
|
+
let STATES;
|
|
535
553
|
const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
|
|
536
554
|
const ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
|
|
537
555
|
|
|
@@ -977,4 +995,4 @@ function useLocale(scope, context) {
|
|
|
977
995
|
const LOCALE_CONTEXT = defineContext("LOCALE_CONTEXT");
|
|
978
996
|
|
|
979
997
|
//#endregion
|
|
980
|
-
export { $fetch, AfterNavigateEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, activeViewTransition, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, onViewTransition, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useQuery, useRoute, useRouter, useRuntime, useSetCookies, useState, useUrl };
|
|
998
|
+
export { $fetch, AfterNavigateEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, STATES, Scope, StopEvent, activeCompute, activeViewTransition, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, onViewTransition, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useQuery, useRoute, useRouter, useRuntime, useSetCookies, useState, useUrl };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -47,5 +47,6 @@ export declare function useFetch<T, TError = Error>(scope: Scope, input: string
|
|
|
47
47
|
execute: () => Promise<T | undefined>;
|
|
48
48
|
};
|
|
49
49
|
export declare function createRuntime(): Promise<Runtime>;
|
|
50
|
+
export declare let STATES: Record<string, unknown>;
|
|
50
51
|
export declare const RUNTIME_CONTEXT: import("..").Descriptor<RuntimeContext<Record<string, unknown>>>;
|
|
51
52
|
export declare const ROUTE_CONTEXT: import("..").Descriptor<RouteContext>;
|