@fluixi/core 1.0.0-alpha.92 → 1.0.0-alpha.94
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/cdn/core.global.js +2 -2
- package/dist/src/cdn/{chunk-MDJLC3PE.mjs → chunk-7XM7Q5VR.mjs} +271 -229
- package/dist/src/cdn/core.cjs +360 -253
- package/dist/src/cdn/core.mjs +92 -20
- package/dist/src/cdn/{router-JYFZP3EZ.mjs → router-VOY43YNM.mjs} +7 -3
- package/dist/src/index.cjs +548 -232
- package/dist/src/index.mjs +549 -224
- package/dist/src/lib/client/chunk-TSXM2PNY.mjs +53 -0
- package/dist/src/lib/client/index.cjs +310 -176
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +33 -18
- package/dist/src/lib/client/index.mjs +86 -15
- package/dist/src/lib/client/{router-PHLUYVQU.mjs → router-BDVPLLYX.mjs} +244 -99
- package/dist/src/lib/context/context.cjs +35 -72
- package/dist/src/lib/context/context.d.ts +45 -291
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +65 -397
- package/dist/src/lib/context/context.mjs +38 -73
- package/dist/src/lib/context/index.cjs +35 -72
- package/dist/src/lib/context/index.d.ts +2 -2
- package/dist/src/lib/context/index.d.ts.map +1 -1
- package/dist/src/lib/context/index.js +1 -5
- package/dist/src/lib/context/index.mjs +38 -73
- package/dist/src/lib/core.cjs +547 -231
- package/dist/src/lib/core.d.ts +5 -3
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +6 -4
- package/dist/src/lib/core.mjs +548 -223
- package/dist/src/lib/env/index.cjs +1 -17
- package/dist/src/lib/env/index.d.ts +2 -14
- package/dist/src/lib/env/index.d.ts.map +1 -1
- package/dist/src/lib/env/index.js +2 -26
- package/dist/src/lib/env/index.mjs +1 -17
- package/dist/src/lib/i18n/index.cjs +17 -2
- package/dist/src/lib/i18n/index.d.ts +10 -0
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +17 -1
- package/dist/src/lib/i18n/index.mjs +17 -2
- package/dist/src/lib/index.cjs +64 -99
- package/dist/src/lib/index.mjs +43 -76
- package/dist/src/lib/isomorphic.cjs +9 -4
- package/dist/src/lib/isomorphic.d.ts +9 -2
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +11 -4
- package/dist/src/lib/isomorphic.mjs +9 -4
- package/dist/src/lib/jsx-runtime/index.cjs +1 -1
- package/dist/src/lib/jsx-runtime/index.mjs +1 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +1 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +2 -2
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +2 -2
- package/dist/src/lib/plugins/index.cjs +3 -3
- package/dist/src/lib/plugins/index.mjs +3 -3
- package/dist/src/lib/plugins/route-codegen.cjs +2 -2
- package/dist/src/lib/plugins/route-codegen.js +1 -1
- package/dist/src/lib/plugins/route-codegen.mjs +2 -2
- package/dist/src/lib/render/index.cjs +1 -1
- package/dist/src/lib/render/index.mjs +1 -1
- package/dist/src/lib/render/versions.cjs +1 -1
- package/dist/src/lib/render/versions.mjs +1 -1
- package/dist/src/lib/router/data.cjs +113 -115
- package/dist/src/lib/router/data.d.ts +63 -10
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +158 -68
- package/dist/src/lib/router/data.mjs +112 -112
- package/dist/src/lib/router/index.cjs +260 -163
- package/dist/src/lib/router/index.d.ts +22 -2
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +165 -22
- package/dist/src/lib/router/index.mjs +244 -143
- package/dist/src/lib/server/index.cjs +1 -1
- package/dist/src/lib/server/index.mjs +1 -1
- package/dist/src/lib/storage/cache.cjs +51 -0
- package/dist/src/lib/storage/cache.d.ts +18 -0
- package/dist/src/lib/storage/cache.d.ts.map +1 -0
- package/dist/src/lib/storage/cache.js +42 -0
- package/dist/src/lib/storage/cache.mjs +30 -0
- package/dist/src/lib/storage/index.cjs +246 -0
- package/dist/src/lib/storage/index.d.ts +83 -0
- package/dist/src/lib/storage/index.d.ts.map +1 -0
- package/dist/src/lib/storage/index.js +179 -0
- package/dist/src/lib/storage/index.mjs +231 -0
- package/dist/src/lib/storage/persisted.cjs +91 -0
- package/dist/src/lib/storage/persisted.d.ts +53 -0
- package/dist/src/lib/storage/persisted.d.ts.map +1 -0
- package/dist/src/lib/storage/persisted.js +75 -0
- package/dist/src/lib/storage/persisted.mjs +70 -0
- package/dist/src/lib/theme/color-scheme.cjs +281 -0
- package/dist/src/lib/theme/color-scheme.d.ts +61 -0
- package/dist/src/lib/theme/color-scheme.d.ts.map +1 -0
- package/dist/src/lib/theme/color-scheme.js +120 -0
- package/dist/src/lib/theme/color-scheme.mjs +265 -0
- package/dist/src/lib/theme/index.cjs +194 -37
- package/dist/src/lib/theme/index.d.ts +23 -11
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +73 -32
- package/dist/src/lib/theme/index.mjs +197 -35
- package/dist/src/lib/theme/provider.cjs +346 -0
- package/dist/src/lib/theme/provider.d.ts +34 -0
- package/dist/src/lib/theme/provider.d.ts.map +1 -0
- package/dist/src/lib/theme/provider.js +60 -0
- package/dist/src/lib/theme/provider.mjs +332 -0
- package/dist/src/routes.cjs +1 -1
- package/dist/src/routes.mjs +1 -1
- package/dist/src/utils.cjs +1 -1
- package/dist/src/utils.mjs +1 -1
- package/dist/src/version.generated.cjs +1 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +1 -1
- package/dist/src/version.generated.mjs +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +18 -11
- package/dist/src/lib/client/chunk-VB567ABU.mjs +0 -133
|
@@ -25,88 +25,37 @@ __export(data_exports, {
|
|
|
25
25
|
action: () => action,
|
|
26
26
|
cache: () => cache,
|
|
27
27
|
createAsync: () => createAsync,
|
|
28
|
+
onRevalidate: () => onRevalidate,
|
|
28
29
|
revalidate: () => revalidate,
|
|
29
30
|
useAction: () => useAction,
|
|
30
31
|
useRouteData: () => useRouteData,
|
|
31
|
-
useSubmission: () => useSubmission
|
|
32
|
+
useSubmission: () => useSubmission,
|
|
33
|
+
useSubmissions: () => useSubmissions
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(data_exports);
|
|
36
|
+
var import_signal2 = require("@fluixi/reactive/signal");
|
|
34
37
|
var import_signal3 = require("@fluixi/reactive/signal");
|
|
35
38
|
|
|
36
|
-
// src/lib/server/hydration.ts
|
|
37
|
-
var import_dom = require("@fluixi/dom");
|
|
38
|
-
var hydrating = false;
|
|
39
|
-
var hydrationDataMap = /* @__PURE__ */ new Map();
|
|
40
|
-
function isHydrating() {
|
|
41
|
-
return hydrating;
|
|
42
|
-
}
|
|
43
|
-
function setHydrationData(key, data) {
|
|
44
|
-
hydrationDataMap.set(key, data);
|
|
45
|
-
}
|
|
46
|
-
function getHydrationData(key) {
|
|
47
|
-
return hydrationDataMap.get(key);
|
|
48
|
-
}
|
|
49
|
-
function clearHydrationData() {
|
|
50
|
-
hydrationDataMap.clear();
|
|
51
|
-
}
|
|
52
|
-
function cleanupHydration() {
|
|
53
|
-
if (typeof window === "undefined") {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const script = document.getElementById("__FLUIXI_HYDRATION__");
|
|
57
|
-
if (script) {
|
|
58
|
-
script.remove();
|
|
59
|
-
}
|
|
60
|
-
const walker = document.createTreeWalker(
|
|
61
|
-
document.body,
|
|
62
|
-
NodeFilter.SHOW_COMMENT,
|
|
63
|
-
null
|
|
64
|
-
);
|
|
65
|
-
const comments = [];
|
|
66
|
-
let node;
|
|
67
|
-
while (node = walker.nextNode()) {
|
|
68
|
-
const comment = node;
|
|
69
|
-
const text = comment.nodeValue || "";
|
|
70
|
-
if (text.startsWith("#") || text.startsWith("/")) {
|
|
71
|
-
comments.push(comment);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
comments.forEach((comment) => comment.remove());
|
|
75
|
-
clearHydrationData();
|
|
76
|
-
}
|
|
77
|
-
if (typeof window !== "undefined") {
|
|
78
|
-
window.addEventListener("load", () => {
|
|
79
|
-
setTimeout(cleanupHydration, 100);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function isServerEnvironment() {
|
|
83
|
-
return (0, import_dom.isServer)();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
39
|
// src/lib/context/context.ts
|
|
87
|
-
var
|
|
40
|
+
var import_dom = require("@fluixi/dom");
|
|
88
41
|
var import_signal = require("@fluixi/reactive/signal");
|
|
89
|
-
var import_signal2 = require("@fluixi/reactive/signal");
|
|
90
42
|
function createContext(defaultValue, name) {
|
|
91
43
|
const context = (0, import_signal.createContext)(defaultValue, name);
|
|
92
|
-
const Provider = (props) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
44
|
+
const Provider = (props) => (
|
|
45
|
+
// Children stay a getter: the reactive Provider reads them after stamping the value on
|
|
46
|
+
// its owner. Reading `props.children` here would render them, and any <Outlet/> in them,
|
|
47
|
+
// before the context exists.
|
|
48
|
+
context.Provider({
|
|
96
49
|
value: props.value,
|
|
97
50
|
get children() {
|
|
98
51
|
return props.children;
|
|
99
52
|
},
|
|
100
53
|
debug: props.debug
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
104
|
-
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
105
|
-
}
|
|
106
|
-
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
54
|
+
})
|
|
55
|
+
);
|
|
107
56
|
return {
|
|
108
57
|
id: context.id,
|
|
109
|
-
Provider: (0,
|
|
58
|
+
Provider: (0, import_dom.asProvider)(Provider),
|
|
110
59
|
defaultValue
|
|
111
60
|
};
|
|
112
61
|
}
|
|
@@ -116,55 +65,75 @@ function useContext(context) {
|
|
|
116
65
|
}
|
|
117
66
|
|
|
118
67
|
// src/lib/router/data.ts
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return
|
|
68
|
+
var revalidationListeners = /* @__PURE__ */ new Set();
|
|
69
|
+
function onRevalidate(listener) {
|
|
70
|
+
revalidationListeners.add(listener);
|
|
71
|
+
return () => void revalidationListeners.delete(listener);
|
|
72
|
+
}
|
|
73
|
+
var reloadMounted = () => {
|
|
74
|
+
for (const listener of [...revalidationListeners]) listener();
|
|
75
|
+
};
|
|
76
|
+
function cache(fn, name, options = {}) {
|
|
77
|
+
const { ttl = Infinity, staleWhileRevalidate = true } = options;
|
|
78
|
+
return (...args) => {
|
|
79
|
+
const store = options.cache ?? (0, import_signal3.currentResourceCache)();
|
|
123
80
|
const key = name + ":" + JSON.stringify(args);
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const promise = Promise.resolve(fn(...args)).then(
|
|
137
|
-
(val) => {
|
|
138
|
-
globalCache.set(key, val);
|
|
139
|
-
inflightRequests.delete(key);
|
|
140
|
-
if (isServerEnvironment()) {
|
|
141
|
-
setHydrationData(key, val);
|
|
81
|
+
const fetchFresh = () => {
|
|
82
|
+
const running = store.inflight.get(key);
|
|
83
|
+
if (running) return running;
|
|
84
|
+
const promise = Promise.resolve(fn(...args)).then(
|
|
85
|
+
(value) => {
|
|
86
|
+
store.set(key, { value, timestamp: Date.now() });
|
|
87
|
+
store.inflight.delete(key);
|
|
88
|
+
return value;
|
|
89
|
+
},
|
|
90
|
+
(error) => {
|
|
91
|
+
store.inflight.delete(key);
|
|
92
|
+
throw error;
|
|
142
93
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
|
|
94
|
+
);
|
|
95
|
+
store.inflight.set(key, promise);
|
|
96
|
+
return promise;
|
|
97
|
+
};
|
|
98
|
+
const hit = store.get(key);
|
|
99
|
+
if (hit && (ttl === Infinity || Date.now() - hit.timestamp <= ttl)) return Promise.resolve(hit.value);
|
|
100
|
+
if (hit && staleWhileRevalidate) {
|
|
101
|
+
fetchFresh().then(reloadMounted, () => void 0);
|
|
102
|
+
return Promise.resolve(hit.value);
|
|
103
|
+
}
|
|
104
|
+
return fetchFresh();
|
|
152
105
|
};
|
|
153
106
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
107
|
+
function revalidate(key, store) {
|
|
108
|
+
const names = typeof key === "string" ? [key] : Array.isArray(key) ? key : null;
|
|
109
|
+
drop(names ?? key, store ?? (0, import_signal3.currentResourceCache)());
|
|
110
|
+
if (names && !store) tellOtherTabs(names);
|
|
111
|
+
}
|
|
112
|
+
function drop(what, store) {
|
|
113
|
+
const matches = Array.isArray(what) ? (k) => what.some((n) => k === n || k.startsWith(n + ":")) : what;
|
|
114
|
+
for (const k of [...store.keys()]) if (matches(k)) store.delete(k);
|
|
115
|
+
reloadMounted();
|
|
116
|
+
}
|
|
117
|
+
var TABS_KEY = "fluixi:revalidate";
|
|
118
|
+
function tellOtherTabs(names) {
|
|
119
|
+
try {
|
|
120
|
+
localStorage.setItem(TABS_KEY, JSON.stringify({ names, at: Date.now() + Math.random() }));
|
|
121
|
+
} catch {
|
|
163
122
|
}
|
|
164
|
-
setRevalidationVersion((v) => v + 1);
|
|
165
123
|
}
|
|
124
|
+
if (typeof window !== "undefined") {
|
|
125
|
+
window.addEventListener("storage", (event) => {
|
|
126
|
+
if (event.key !== TABS_KEY || !event.newValue) return;
|
|
127
|
+
try {
|
|
128
|
+
const names = JSON.parse(event.newValue).names;
|
|
129
|
+
if (Array.isArray(names) && names.every((n) => typeof n === "string")) drop(names, (0, import_signal3.currentResourceCache)());
|
|
130
|
+
} catch {
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
globalThis[/* @__PURE__ */ Symbol.for("fluixi.revalidate")] = (names) => revalidate(names);
|
|
166
135
|
function createAsync(fetcher, source) {
|
|
167
|
-
const [data] = (0,
|
|
136
|
+
const [data] = (0, import_signal2.createResource)(source || (() => true), fetcher);
|
|
168
137
|
return data;
|
|
169
138
|
}
|
|
170
139
|
var submissionState = /* @__PURE__ */ new Map();
|
|
@@ -172,24 +141,44 @@ function getSubmissionSignal(url) {
|
|
|
172
141
|
if (!submissionState.has(url)) {
|
|
173
142
|
submissionState.set(
|
|
174
143
|
url,
|
|
175
|
-
(0,
|
|
144
|
+
(0, import_signal2.createSignal)(void 0)
|
|
176
145
|
);
|
|
177
146
|
}
|
|
178
147
|
return submissionState.get(url);
|
|
179
148
|
}
|
|
180
|
-
|
|
149
|
+
var submissionsState = /* @__PURE__ */ new Map();
|
|
150
|
+
function getSubmissionsSignal(url) {
|
|
151
|
+
if (!submissionsState.has(url)) submissionsState.set(url, (0, import_signal2.createSignal)([]));
|
|
152
|
+
return submissionsState.get(url);
|
|
153
|
+
}
|
|
154
|
+
function action(fn, name, options = {}) {
|
|
181
155
|
const actionUrl = name || fn.name || "action";
|
|
182
156
|
const submit = async (input) => {
|
|
183
157
|
const [, setSubmission] = getSubmissionSignal(actionUrl);
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
158
|
+
const [, setSubmissions] = getSubmissionsSignal(actionUrl);
|
|
159
|
+
let entry;
|
|
160
|
+
const drop2 = () => setSubmissions((list) => list.filter((s) => s !== entry));
|
|
161
|
+
const settle = (next) => {
|
|
162
|
+
setSubmissions((list) => list.map((s) => s === entry ? next : s));
|
|
163
|
+
entry = next;
|
|
164
|
+
};
|
|
165
|
+
const clear = () => {
|
|
166
|
+
setSubmission(void 0);
|
|
167
|
+
drop2();
|
|
168
|
+
};
|
|
169
|
+
const retry = () => {
|
|
170
|
+
drop2();
|
|
171
|
+
return submit(input);
|
|
172
|
+
};
|
|
173
|
+
entry = {
|
|
187
174
|
input,
|
|
188
175
|
// Approximate type for tracking
|
|
189
176
|
pending: true,
|
|
190
177
|
clear,
|
|
191
178
|
retry
|
|
192
|
-
}
|
|
179
|
+
};
|
|
180
|
+
setSubmission(entry);
|
|
181
|
+
setSubmissions((list) => [...list, entry]);
|
|
193
182
|
try {
|
|
194
183
|
const result = await fn(input);
|
|
195
184
|
setSubmission({
|
|
@@ -199,26 +188,35 @@ function action(fn, name) {
|
|
|
199
188
|
clear,
|
|
200
189
|
retry
|
|
201
190
|
});
|
|
191
|
+
drop2();
|
|
192
|
+
const stale = typeof options.invalidates === "function" ? options.invalidates(result) : options.invalidates;
|
|
193
|
+
for (const key of stale ?? []) revalidate(key);
|
|
202
194
|
return result;
|
|
203
195
|
} catch (error) {
|
|
204
|
-
|
|
196
|
+
const failed = {
|
|
205
197
|
input,
|
|
206
198
|
error,
|
|
207
199
|
pending: false,
|
|
208
200
|
clear,
|
|
209
201
|
retry
|
|
210
|
-
}
|
|
202
|
+
};
|
|
203
|
+
setSubmission(failed);
|
|
204
|
+
settle(failed);
|
|
211
205
|
throw error;
|
|
212
206
|
}
|
|
213
207
|
};
|
|
214
208
|
submit.url = actionUrl;
|
|
215
|
-
submit.with = (args) => action((...a) => fn(args, ...a), name);
|
|
209
|
+
submit.with = (args) => action((...a) => fn(args, ...a), name, options);
|
|
216
210
|
return submit;
|
|
217
211
|
}
|
|
218
212
|
function useSubmission(actionFn) {
|
|
219
213
|
const [submission] = getSubmissionSignal(actionFn.url);
|
|
220
214
|
return submission;
|
|
221
215
|
}
|
|
216
|
+
function useSubmissions(actionFn) {
|
|
217
|
+
const [submissions] = getSubmissionsSignal(actionFn.url);
|
|
218
|
+
return submissions;
|
|
219
|
+
}
|
|
222
220
|
function useAction(actionFn) {
|
|
223
221
|
return actionFn;
|
|
224
222
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @module @fluixi/core/router/data
|
|
3
3
|
*/
|
|
4
4
|
import { type Accessor, Resource } from '@fluixi/reactive/signal';
|
|
5
|
+
import { type ResourceCache } from '@fluixi/reactive/signal';
|
|
5
6
|
export type CacheFn<T, Args extends any[]> = (...args: Args) => Promise<T> | T | undefined;
|
|
6
7
|
export interface Action<T, Args extends any[]> {
|
|
7
8
|
(...args: Args): Promise<T>;
|
|
@@ -16,20 +17,41 @@ export interface Submission<T, Args extends any[]> {
|
|
|
16
17
|
clear: () => void;
|
|
17
18
|
retry: () => void;
|
|
18
19
|
}
|
|
20
|
+
export interface CacheOptions {
|
|
21
|
+
/** Milliseconds a value stays fresh. Default: until revalidated. */
|
|
22
|
+
ttl?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Once stale, return the old value at once and refresh in the background; the routes on
|
|
25
|
+
* screen then load again and pick up the new one. Default true.
|
|
26
|
+
*/
|
|
27
|
+
staleWhileRevalidate?: boolean;
|
|
28
|
+
/** Where entries live. Defaults to the request's cache on the server and the page's in a browser. */
|
|
29
|
+
cache?: ResourceCache;
|
|
30
|
+
}
|
|
31
|
+
/** @internal: the router registers each layer's refetch here. */
|
|
32
|
+
export declare function onRevalidate(listener: () => void): () => void;
|
|
19
33
|
/**
|
|
20
|
-
*
|
|
34
|
+
* A function whose results are kept by name and arguments: route data that should not be
|
|
35
|
+
* fetched again on every visit.
|
|
36
|
+
*
|
|
37
|
+
* Readers of the same key share one request in flight. Entries live in the request's cache on
|
|
38
|
+
* the server, so visitors never share one, and in the page's cache in a browser.
|
|
21
39
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const organisations = cache(() => api.get('/api/v1/organizations'), 'orgs', { ttl: 30_000 });
|
|
43
|
+
* export const routeData = () => organisations();
|
|
44
|
+
* // after a change:
|
|
45
|
+
* revalidate('orgs');
|
|
46
|
+
* ```
|
|
26
47
|
*/
|
|
27
|
-
export declare function cache<T, Args extends any[]>(fn: (...args: Args) => Promise<T> | T, name: string): (...args: Args) => Promise<T>;
|
|
48
|
+
export declare function cache<T, Args extends any[]>(fn: (...args: Args) => Promise<T> | T, name: string, options?: CacheOptions): (...args: Args) => Promise<T>;
|
|
28
49
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
50
|
+
* Drops cached entries, by name (`'orgs'` matches every `orgs:` key), several names, or a
|
|
51
|
+
* predicate, then loads the data of the routes on screen again. What is still cached is
|
|
52
|
+
* served from the cache, so only the dropped entries are fetched.
|
|
31
53
|
*/
|
|
32
|
-
export declare function revalidate(key: string | ((key: string) => boolean)): void;
|
|
54
|
+
export declare function revalidate(key: string | string[] | ((key: string) => boolean), store?: ResourceCache): void;
|
|
33
55
|
/**
|
|
34
56
|
* Create an async resource from a promise or cache function
|
|
35
57
|
*/
|
|
@@ -37,11 +59,37 @@ export declare function createAsync<T, S extends any = true>(fetcher: (source: S
|
|
|
37
59
|
/**
|
|
38
60
|
* Create a server action
|
|
39
61
|
*/
|
|
40
|
-
export
|
|
62
|
+
export interface ActionOptions<T> {
|
|
63
|
+
/**
|
|
64
|
+
* Cache names this action changes (`['orgs']`), or a function of its result that returns
|
|
65
|
+
* them. They are revalidated when it succeeds, so the routes on screen show the change.
|
|
66
|
+
*/
|
|
67
|
+
invalidates?: string[] | ((result: T) => string[]);
|
|
68
|
+
}
|
|
69
|
+
export declare function action<T, Args extends any[]>(fn: (...args: Args) => Promise<T> | T, name?: string, options?: ActionOptions<T>): Action<T, Args>;
|
|
41
70
|
/**
|
|
42
71
|
* Hook to track action submission state
|
|
43
72
|
*/
|
|
44
73
|
export declare function useSubmission<T, Args extends any[]>(actionFn: Action<T, Args>): Accessor<Submission<T, Args> | undefined>;
|
|
74
|
+
/**
|
|
75
|
+
* Every call of `actionFn` still in flight, and the ones that failed, oldest first. One entry
|
|
76
|
+
* per call, so concurrent calls do not overwrite each other. A call that succeeds leaves the
|
|
77
|
+
* list; one that fails stays with its `error` until `retry()` or `clear()`.
|
|
78
|
+
*
|
|
79
|
+
* The optimistic pattern: render the server's rows, then the pending entries mapped to the
|
|
80
|
+
* same shape. When a call succeeds its entry goes and the server row takes its place; when it
|
|
81
|
+
* fails it stops being pending, so it leaves the optimistic rows by itself.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* const moves = useSubmissions(moveDeal);
|
|
86
|
+
* const rows = $memo(() => [
|
|
87
|
+
* ...deals(),
|
|
88
|
+
* ...moves().filter((s) => s.pending).map((s) => ({ ...s.input, pending: true })),
|
|
89
|
+
* ]);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function useSubmissions<T, Args extends any[]>(actionFn: Action<T, Args>): Accessor<Submission<T, Args>[]>;
|
|
45
93
|
/**
|
|
46
94
|
* Hook to get action executor
|
|
47
95
|
*/
|
|
@@ -61,6 +109,11 @@ export interface RouteDataArgs {
|
|
|
61
109
|
pathname: string;
|
|
62
110
|
search: string;
|
|
63
111
|
});
|
|
112
|
+
/**
|
|
113
|
+
* What the route's `routeDeps` export returned when this load started: app-wide values the
|
|
114
|
+
* data depends on, such as the signed-in user. Key a `cache()` call by them.
|
|
115
|
+
*/
|
|
116
|
+
deps?: unknown;
|
|
64
117
|
}
|
|
65
118
|
export type RouteLoadFunc = (args: RouteDataArgs, owner?: any, isCancelled?: () => boolean) => any;
|
|
66
119
|
export declare const RouteDataContext: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/lib/router/data.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAGL,KAAK,QAAQ,EAEb,QAAQ,EACT,MA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