Skip to content

Commit 7b5e650

Browse files
committed
fix
1 parent 4c9fde9 commit 7b5e650

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3233
-49
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
10+
# Ignore files for PNPM, NPM and YARN
11+
pnpm-lock.yaml
12+
package-lock.json
13+
yarn.lock
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/** @type { import("eslint").Linter.Config } */
2+
module.exports = {
3+
root: true,
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:svelte/recommended',
8+
'prettier'
9+
],
10+
parser: '@typescript-eslint/parser',
11+
plugins: ['@typescript-eslint'],
12+
parserOptions: {
13+
sourceType: 'module',
14+
ecmaVersion: 2020,
15+
extraFileExtensions: ['.svelte']
16+
},
17+
env: {
18+
browser: true,
19+
es2017: true,
20+
node: true
21+
},
22+
overrides: [
23+
{
24+
files: ['*.svelte'],
25+
parser: 'svelte-eslint-parser',
26+
parserOptions: {
27+
parser: '@typescript-eslint/parser'
28+
}
29+
}
30+
]
31+
};
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
vite.config.js.timestamp-*
10+
vite.config.ts.timestamp-*

examples/svelte/svelte-melt/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore files for PNPM, NPM and YARN
2+
pnpm-lock.yaml
3+
package-lock.json
4+
yarn.lock
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"useTabs": true,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"printWidth": 100,
6+
"plugins": ["prettier-plugin-svelte"],
7+
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
8+
}

examples/svelte/svelte-melt/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# create-svelte
2+
3+
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
4+
5+
## Creating a project
6+
7+
If you're seeing this, you've probably already done this step. Congrats!
8+
9+
```bash
10+
# create a new project in the current directory
11+
npm create svelte@latest
12+
13+
# create a new project in my-app
14+
npm create svelte@latest my-app
15+
```
16+
17+
## Developing
18+
19+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20+
21+
```bash
22+
npm run dev
23+
24+
# or start the server and open the app in a new browser tab
25+
npm run dev -- --open
26+
```
27+
28+
## Building
29+
30+
To create a production version of your app:
31+
32+
```bash
33+
npm run build
34+
```
35+
36+
You can preview the production build with `npm run preview`.
37+
38+
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "svelte-melt",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite dev --port 3000",
7+
"build": "vite build",
8+
"preview": "vite preview",
9+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
10+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
11+
"lint": "prettier --check . && eslint .",
12+
"format": "prettier --write ."
13+
},
14+
"devDependencies": {
15+
"@sveltejs/adapter-auto": "^3.1.1",
16+
"@sveltejs/kit": "^2.5.0",
17+
"@sveltejs/vite-plugin-svelte": "^3.0.2",
18+
"@types/eslint": "8.56.2",
19+
"@typescript-eslint/eslint-plugin": "^5.62.0",
20+
"@typescript-eslint/parser": "^5.62.0",
21+
"eslint": "^8.56.0",
22+
"eslint-config-prettier": "^9.1.0",
23+
"eslint-plugin-svelte": "^2.35.1",
24+
"prettier": "^3.2.5",
25+
"prettier-plugin-svelte": "^3.2.1",
26+
"svelte": "5.0.0-next.66",
27+
"svelte-check": "^3.6.4",
28+
"tslib": "^2.6.2",
29+
"typescript": "^5.3.3",
30+
"vite": "^5.1.2"
31+
},
32+
"type": "module",
33+
"dependencies": {
34+
"@tanstack/svelte-query-devtools": "workspace:^",
35+
"svelte-query": "workspace:*"
36+
}
37+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See https://kit.svelte.dev/docs/types#app
2+
// for information about these interfaces
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface PageState {}
9+
// interface Platform {}
10+
}
11+
}
12+
13+
export {};
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
%sveltekit.head%
8+
</head>
9+
<body data-sveltekit-preload-data="hover">
10+
<div style="display: contents">%sveltekit.body%</div>
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script lang="ts">
2+
import { QueryClientProvider, QueryClient } from 'svelte-query/dev';
3+
import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools/dev';
4+
5+
const queryClient = new QueryClient();
6+
</script>
7+
8+
<QueryClientProvider client={queryClient}>
9+
<SvelteQueryDevtools />
10+
<main>
11+
<slot />
12+
</main>
13+
</QueryClientProvider>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="ts">
2+
import Simple from './paginate.svelte';
3+
import Cache from './cacheUpdate.svelte';
4+
import Simple1 from './test.svelte';
5+
</script>
6+
7+
<h1>testing pagination with createQuery</h1>
8+
<Simple />
9+
<hr />
10+
11+
<h1>testing cache update</h1>
12+
<Cache />
13+
<hr />
14+
-------------
15+
16+
<Simple1 />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const csr = true;
2+
3+
export const ssr = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<script lang="ts">
2+
import { createMutation, createQuery, hashKey, useQueryClient } from 'svelte-query/dev';
3+
import { bookFilterStore } from './store.svelte';
4+
import { unstate } from 'svelte';
5+
let a = { a: 1 };
6+
let b = ['cache update tester', bookFilterStore];
7+
8+
const data = createQuery(() => {
9+
return {
10+
queryKey: b,
11+
queryFn: async () => {
12+
const s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'].map((v) => {
13+
return { title: v };
14+
});
15+
if (Math.abs(bookFilterStore.paginate.page % 2) == 1) {
16+
return s.slice(0, 5);
17+
}
18+
return s.slice(5, 6);
19+
},
20+
staleTime: 5000000
21+
};
22+
});
23+
const client = useQueryClient();
24+
const update = createMutation({
25+
mutationFn: () => {
26+
return ['a new list of items', 'a'];
27+
},
28+
onSuccess: (v) => {
29+
// console.log(hashKey(b.map((v) => unstate(v))));
30+
// console.log(hashKey(b));
31+
// console.log('test hash', hashKey(b) === hashKey(b.map((v) => unstate(v))));
32+
const k = b.map((v) => unstate(v));
33+
client.setQueryData(k, (v) => {
34+
debugger;
35+
v[0].title = 'faker';
36+
return v;
37+
});
38+
}
39+
});
40+
/* const querycache = useQueryClient().getQueryCache();
41+
$effect(() => {
42+
if (data.fetchStatus) {
43+
console.log(data.fetchStatus);
44+
}
45+
const ret = querycache.find({ queryKey: b, exact: false });
46+
//console.log('find in query cache', ret);
47+
}); */
48+
</script>
49+
50+
<button
51+
onclick={() => {
52+
update.mutate();
53+
}}>update cache</button
54+
>
55+
56+
{data.fetchStatus}
57+
{data.isLoading}
58+
{data.isFetching}
59+
{data.isRefetching}
60+
<button
61+
onclick={() => {
62+
console.log('click +1');
63+
bookFilterStore.paginate.page += 1;
64+
}}>next</button
65+
>
66+
<button
67+
onclick={() => {
68+
console.log('click -1');
69+
bookFilterStore.paginate.page -= 1;
70+
}}>prev</button
71+
>
72+
{bookFilterStore.paginate.page}
73+
<pre>{JSON.stringify(data.data, null, 1)}</pre>
74+
{#each data?.data ?? [] as item}
75+
<div>{item.title}</div>
76+
{/each}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script lang="ts">
2+
import { createQuery, useQueryClient } from 'svelte-query/dev';
3+
import { bookFilterStore } from './store.svelte';
4+
import { unstate } from 'svelte';
5+
let a = { a: 1 };
6+
let b = ['hi', bookFilterStore];
7+
const data = createQuery(() => {
8+
return {
9+
queryKey: ['hi', bookFilterStore],
10+
queryFn: async () => {
11+
const s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'].map((v) => {
12+
return { title: v };
13+
});
14+
if (Math.abs(bookFilterStore.paginate.page % 2) == 1) {
15+
return s.slice(0, 5);
16+
}
17+
return s.slice(5, 6);
18+
},
19+
staleTime: 5000
20+
};
21+
});
22+
/* const querycache = useQueryClient().getQueryCache();
23+
$effect(() => {
24+
if (data.fetchStatus) {
25+
console.log(data.fetchStatus);
26+
}
27+
const ret = querycache.find({ queryKey: b, exact: false });
28+
//console.log('find in query cache', ret);
29+
}); */
30+
</script>
31+
32+
<h2>testing create query with list</h2>
33+
34+
{data.fetchStatus}
35+
{data.isLoading}
36+
{data.isFetching}
37+
{data.isRefetching}
38+
<button
39+
onclick={() => {
40+
console.log('click +1');
41+
bookFilterStore.paginate.page += 1;
42+
}}>next</button
43+
>
44+
<button
45+
onclick={() => {
46+
console.log('click -1');
47+
bookFilterStore.paginate.page -= 1;
48+
}}>prev</button
49+
>
50+
{bookFilterStore.paginate.page}
51+
{#each data?.data ?? [] as item}
52+
<div>{item.title}</div>
53+
{/each}

0 commit comments

Comments
 (0)