Skip to content

Commit 068e37f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feat/useStickToBottom
2 parents 4d56f9c + a58c368 commit 068e37f

File tree

13 files changed

+1607
-12
lines changed

13 files changed

+1607
-12
lines changed

packages/runed/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# runed
22

3+
## 0.24.0
4+
5+
### Minor Changes
6+
7+
- feat: add `resource` that watches dependencies and runs async data fetching
8+
([#218](https://github.com/svecosystem/runed/pull/218))
9+
310
## 0.23.4
411

512
### Patch Changes

packages/runed/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "runed",
3-
"version": "0.23.4",
3+
"version": "0.24.0",
44
"type": "module",
55
"svelte": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -59,6 +59,7 @@
5959
"@vitest/coverage-v8": "^1.5.1",
6060
"@vitest/ui": "^1.6.0",
6161
"jsdom": "^24.0.0",
62+
"msw": "^2.7.0",
6263
"publint": "^0.1.9",
6364
"resize-observer-polyfill": "^1.5.1",
6465
"svelte": "^5.11.0",

packages/runed/src/lib/utilities/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export * from "./persisted-state/index.js";
2121
export * from "./use-geolocation/index.js";
2222
export * from "./context/index.js";
2323
export * from "./is-in-viewport/index.js";
24+
export * from "./resource/index.js";
2425
export * from "./use-stick-to-bottom/index.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./resource.svelte.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { http, delay, HttpResponse } from "msw";
2+
3+
export type ResponseData = {
4+
id: number;
5+
name: string;
6+
email: string;
7+
};
8+
9+
export type SearchResponseData = {
10+
results: { id: number; title: string }[];
11+
page: number;
12+
total: number;
13+
};
14+
15+
export const handlers = [
16+
// Basic user endpoint
17+
http.get("https://api.example.com/users/:id", async ({ params }) => {
18+
await delay(50);
19+
return HttpResponse.json({
20+
id: Number(params.id),
21+
name: `User ${params.id}`,
22+
email: `user${params.id}@example.com`,
23+
});
24+
}),
25+
26+
// Search endpoint with query params
27+
http.get("https://api.example.com/search", ({ request }) => {
28+
const url = new URL(request.url);
29+
const query = url.searchParams.get("q");
30+
const page = Number(url.searchParams.get("page")) || 1;
31+
32+
return HttpResponse.json({
33+
results: [
34+
{ id: page * 1, title: `Result 1 for ${query}` },
35+
{ id: page * 2, title: `Result 2 for ${query}` },
36+
],
37+
page,
38+
total: 10,
39+
});
40+
}),
41+
42+
// Endpoint that can fail
43+
http.get("https://api.example.com/error-prone", () => {
44+
return new HttpResponse(null, { status: 500 });
45+
}),
46+
];

0 commit comments

Comments
 (0)