jazz-svelte 0.8.38 → 0.8.39
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Provider.svelte +1 -1
- package/dist/Provider.svelte.d.ts +1 -1
- package/dist/jazz.svelte.js +16 -7
- package/dist/tests/ProviderTestComponent.svelte +14 -0
- package/dist/tests/ProviderTestComponent.svelte.d.ts +5 -0
- package/dist/tests/TestComponent.svelte +17 -0
- package/dist/tests/TestComponent.svelte.d.ts +9 -0
- package/package.json +14 -6
package/dist/Provider.svelte
CHANGED
package/dist/jazz.svelte.js
CHANGED
@@ -38,12 +38,22 @@ export function createJazzApp({ AccountSchema = Account } = {}) {
|
|
38
38
|
if (!('me' in ctx.current)) {
|
39
39
|
throw new Error("useAccount can't be used in a JazzProvider with auth === 'guest' - consider using useAccountOrGuest()");
|
40
40
|
}
|
41
|
+
// If no depth is specified, return the context's me directly
|
42
|
+
if (depth === undefined) {
|
43
|
+
return {
|
44
|
+
get me() {
|
45
|
+
return ctx.current.me;
|
46
|
+
},
|
47
|
+
logOut() {
|
48
|
+
return ctx.current?.logOut();
|
49
|
+
}
|
50
|
+
};
|
51
|
+
}
|
52
|
+
// If depth is specified, use useCoState to get the deeply loaded version
|
41
53
|
const me = useCoState(ctx.current.me.constructor, ctx.current.me.id, depth);
|
42
54
|
return {
|
43
55
|
get me() {
|
44
|
-
|
45
|
-
return;
|
46
|
-
return depth === undefined ? me.current || ctx.current.me : me.current;
|
56
|
+
return me.current;
|
47
57
|
},
|
48
58
|
logOut() {
|
49
59
|
return ctx.current?.logOut();
|
@@ -94,16 +104,15 @@ export function createJazzApp({ AccountSchema = Account } = {}) {
|
|
94
104
|
let state = $state.raw(undefined);
|
95
105
|
const observable = $state.raw(createCoValueObservable());
|
96
106
|
// Effect to handle subscription
|
107
|
+
// TODO: Possibly memoise this, to avoid re-subscribing
|
97
108
|
$effect(() => {
|
98
109
|
// Reset state when dependencies change
|
99
110
|
state = undefined;
|
100
|
-
// Get latest values
|
101
|
-
const currentCtx = ctx.current;
|
102
111
|
// Return early if no context or id, effectively cleaning up any previous subscription
|
103
|
-
if (!
|
112
|
+
if (!ctx?.current || !id)
|
104
113
|
return;
|
105
114
|
// Setup subscription with current values
|
106
|
-
return observable.subscribe(Schema, id, 'me' in
|
115
|
+
return observable.subscribe(Schema, id, 'me' in ctx.current ? ctx.current.me : ctx.current.guest, depth, () => {
|
107
116
|
// Get current value from our stable observable
|
108
117
|
state = observable.getCurrentValue();
|
109
118
|
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<script lang="ts">
|
2
|
+
import { createJazzApp } from '../jazz.svelte';
|
3
|
+
|
4
|
+
const { Provider } = createJazzApp();
|
5
|
+
const {auth} = $props();
|
6
|
+
</script>
|
7
|
+
|
8
|
+
<div data-testid="provider-test">
|
9
|
+
<Provider {auth} peer="wss://cloud.jazz.tools/?key=jazz-svelte-test">
|
10
|
+
{#if auth}
|
11
|
+
<span data-testid="provider-auth-test">{JSON.stringify(auth)}</span>
|
12
|
+
{/if}
|
13
|
+
</Provider>
|
14
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<script lang="ts">
|
2
|
+
import { createJazzApp } from '../jazz.svelte';
|
3
|
+
import type { Account, CoValueClass, DepthsIn, ID } from 'jazz-tools';
|
4
|
+
|
5
|
+
const { schema, id = undefined, depth = {} } = $props<{
|
6
|
+
schema: CoValueClass<any>;
|
7
|
+
id?: ID<Account>;
|
8
|
+
depth?: DepthsIn<Account>;
|
9
|
+
}>();
|
10
|
+
|
11
|
+
const app = createJazzApp();
|
12
|
+
const result = $derived(app.useCoState(schema, id, depth));
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<div data-testid="test-component">
|
16
|
+
<div data-testid="current-value">{JSON.stringify(result.current)}</div>
|
17
|
+
</div>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
type $$ComponentProps = {
|
2
|
+
schema: CoValueClass<any>;
|
3
|
+
id?: ID<Account>;
|
4
|
+
depth?: DepthsIn<Account>;
|
5
|
+
};
|
6
|
+
import type { Account, CoValueClass, DepthsIn, ID } from 'jazz-tools';
|
7
|
+
declare const TestComponent: import("svelte").Component<$$ComponentProps, {}, "">;
|
8
|
+
type TestComponent = ReturnType<typeof TestComponent>;
|
9
|
+
export default TestComponent;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-svelte",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.39",
|
4
4
|
"files": [
|
5
5
|
"dist",
|
6
6
|
"!dist/**/*.test.*",
|
@@ -25,12 +25,16 @@
|
|
25
25
|
"@sveltejs/adapter-vercel": "^5.5.0",
|
26
26
|
"@sveltejs/kit": "^2.0.0",
|
27
27
|
"@sveltejs/package": "^2.0.0",
|
28
|
-
"@sveltejs/vite-plugin-svelte": "^4.0.
|
28
|
+
"@sveltejs/vite-plugin-svelte": "^4.0.1",
|
29
|
+
"@testing-library/jest-dom": "^6.6.3",
|
30
|
+
"@testing-library/svelte": "^5.2.6",
|
29
31
|
"@types/eslint": "^9.6.0",
|
32
|
+
"@vitest/coverage-v8": "1.5.3",
|
30
33
|
"eslint": "^9.7.0",
|
31
34
|
"eslint-config-prettier": "^9.1.0",
|
32
35
|
"eslint-plugin-svelte": "^2.36.0",
|
33
36
|
"globals": "^15.0.0",
|
37
|
+
"jsdom": "^25.0.1",
|
34
38
|
"prettier": "^3.3.2",
|
35
39
|
"prettier-plugin-svelte": "^3.2.6",
|
36
40
|
"publint": "^0.2.0",
|
@@ -38,11 +42,12 @@
|
|
38
42
|
"svelte-check": "^4.0.0",
|
39
43
|
"typescript": "^5.0.0",
|
40
44
|
"typescript-eslint": "^8.0.0",
|
41
|
-
"vite": "^5.0.11"
|
45
|
+
"vite": "^5.0.11",
|
46
|
+
"vitest": "1.5.3"
|
42
47
|
},
|
43
48
|
"dependencies": {
|
44
|
-
"jazz-browser": "0.8.
|
45
|
-
"jazz-tools": "0.8.
|
49
|
+
"jazz-browser": "0.8.39",
|
50
|
+
"jazz-tools": "0.8.39"
|
46
51
|
},
|
47
52
|
"scripts": {
|
48
53
|
"dev": "vite dev",
|
@@ -54,6 +59,9 @@
|
|
54
59
|
"format": "prettier --write .",
|
55
60
|
"lint": "prettier --check . && eslint .",
|
56
61
|
"format-and-lint": "pnpm run format && pnpm run lint",
|
57
|
-
"format-and-lint:fix": "pnpm run format --write && pnpm run lint --fix"
|
62
|
+
"format-and-lint:fix": "pnpm run format --write && pnpm run lint --fix",
|
63
|
+
"test": "vitest run",
|
64
|
+
"test:watch": "vitest",
|
65
|
+
"test:coverage": "vitest --coverage"
|
58
66
|
}
|
59
67
|
}
|