@revojs/vue 0.1.55 → 0.1.57
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/client/index.js +6 -3
- package/dist/runtime/main.vue +15 -16
- package/package.json +1 -1
package/dist/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { customRef, inject, isRef, onScopeDispose, ref, toValue, watch } from "vue";
|
|
1
|
+
import { customRef, getCurrentScope, inject, isRef, onScopeDispose, ref, toValue, watch } from "vue";
|
|
2
2
|
import { defineContext, defineHook, fetch, getState, isClient, isServer, sendRedirect, setState } from "revojs";
|
|
3
3
|
//#region src/client/index.ts
|
|
4
4
|
function useScope() {
|
|
@@ -72,9 +72,12 @@ async function useAsync(name, invoke, defaultOptions) {
|
|
|
72
72
|
}
|
|
73
73
|
async function useFetch(input, options) {
|
|
74
74
|
const scope = useScope();
|
|
75
|
+
const effectScope = getCurrentScope();
|
|
75
76
|
const { state, isLoading, refresh } = await useAsync(input, () => fetch(scope, toValue(input), options), options);
|
|
76
|
-
if (isClient && (isRef(input) || typeof input === "function"))
|
|
77
|
-
|
|
77
|
+
if (isClient && (isRef(input) || typeof input === "function")) effectScope?.run(() => {
|
|
78
|
+
watch(input, async (next, previous) => {
|
|
79
|
+
if (next !== previous) await refresh();
|
|
80
|
+
}, { flush: "post" });
|
|
78
81
|
});
|
|
79
82
|
return {
|
|
80
83
|
state,
|
package/dist/runtime/main.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<Suspense>
|
|
2
|
+
<Suspense :key>
|
|
3
3
|
<component :is="route" v-if="route" />
|
|
4
4
|
</Suspense>
|
|
5
5
|
</template>
|
|
@@ -10,12 +10,25 @@ import { isClient, Router, RouterContext, useUrl } from "revojs";
|
|
|
10
10
|
import { computed, h, onErrorCaptured, onScopeDispose, shallowRef, type Component } from "vue";
|
|
11
11
|
import { CLIENT_ERROR_CONTEXT, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, useScope } from "../client";
|
|
12
12
|
|
|
13
|
+
const router = new Router<Component>();
|
|
14
|
+
|
|
13
15
|
const scope = useScope();
|
|
14
16
|
|
|
15
17
|
const error = shallowRef<Error>();
|
|
16
18
|
const context = shallowRef<RouterContext<Component>>();
|
|
17
19
|
|
|
18
|
-
const
|
|
20
|
+
const key = computed(() => context.value?.segments.join("/"));
|
|
21
|
+
|
|
22
|
+
const route = computed(() => {
|
|
23
|
+
if (!context.value?.route) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return context.value.hooks.reduceRight(
|
|
28
|
+
(previous, hook) => h(hook, null, { default: () => (error.value === undefined ? previous : undefined) }),
|
|
29
|
+
h(context.value.route),
|
|
30
|
+
);
|
|
31
|
+
});
|
|
19
32
|
|
|
20
33
|
for (const path in pages) {
|
|
21
34
|
const segments = path.split("/");
|
|
@@ -33,20 +46,6 @@ for (const path in pages) {
|
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
48
|
|
|
36
|
-
const route = computed(() => {
|
|
37
|
-
if (context.value?.route) {
|
|
38
|
-
const route = h(context.value.route);
|
|
39
|
-
|
|
40
|
-
return context.value.hooks.reduceRight(
|
|
41
|
-
(previous, hook) =>
|
|
42
|
-
h(hook, null, {
|
|
43
|
-
default: () => (error.value === undefined ? previous : undefined),
|
|
44
|
-
}),
|
|
45
|
-
route,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
49
|
const fetch = () => {
|
|
51
50
|
const next = useUrl(scope);
|
|
52
51
|
|