jazz-svelte 0.14.20 → 0.14.21
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/jazz.class.svelte.d.ts +1 -5
- package/dist/jazz.class.svelte.js +79 -101
- package/dist/tests/components/CoState/UpdateNestedValue.svelte +3 -1
- package/dist/tests/components/CoState/UpdateNestedValueAccount.svelte +7 -1
- package/dist/tests/components/CoState/UpdateNestedValueAccount.svelte.d.ts +2 -17
- package/package.json +5 -5
@@ -1,11 +1,9 @@
|
|
1
|
-
import type { Account, AccountClass, AnyAccountSchema, CoValueFromRaw, CoValueOrZodSchema, InstanceOfSchema, Loaded, ResolveQuery, ResolveQueryStrict } from
|
1
|
+
import type { Account, AccountClass, AnyAccountSchema, CoValueFromRaw, CoValueOrZodSchema, InstanceOfSchema, Loaded, ResolveQuery, ResolveQueryStrict } from 'jazz-tools';
|
2
2
|
export declare class CoState<V extends CoValueOrZodSchema, R extends ResolveQuery<V> = true> {
|
3
3
|
#private;
|
4
4
|
constructor(Schema: V, id: string | undefined | null | (() => string | undefined | null), options?: {
|
5
5
|
resolve?: ResolveQueryStrict<V, R>;
|
6
6
|
});
|
7
|
-
subscribeTo(): void;
|
8
|
-
updateValue(value: Loaded<V, R> | undefined | null): void;
|
9
7
|
get current(): Loaded<V, R> | null | undefined;
|
10
8
|
}
|
11
9
|
export declare class AccountCoState<A extends (AccountClass<Account> & CoValueFromRaw<Account>) | AnyAccountSchema, R extends ResolveQuery<A> = true> {
|
@@ -13,9 +11,7 @@ export declare class AccountCoState<A extends (AccountClass<Account> & CoValueFr
|
|
13
11
|
constructor(Schema: A, options?: {
|
14
12
|
resolve?: ResolveQueryStrict<A, R>;
|
15
13
|
});
|
16
|
-
subscribeTo(): void;
|
17
14
|
logOut: () => void;
|
18
|
-
updateValue(value: Loaded<A, R> | undefined | null): void;
|
19
15
|
get current(): Loaded<A, R> | null | undefined;
|
20
16
|
get agent(): import("jazz-tools").AnonymousJazzAgent | InstanceOfSchema<A>;
|
21
17
|
}
|
@@ -1,132 +1,110 @@
|
|
1
|
-
import { createSubscriber } from
|
2
|
-
import { getJazzContext } from
|
3
|
-
import { anySchemaToCoSchema, subscribeToCoValue } from
|
1
|
+
import { createSubscriber } from 'svelte/reactivity';
|
2
|
+
import { getJazzContext } from './jazz.svelte';
|
3
|
+
import { anySchemaToCoSchema, subscribeToCoValue } from 'jazz-tools';
|
4
4
|
export class CoState {
|
5
5
|
#value = undefined;
|
6
|
-
#
|
7
|
-
#ctx = $derived(getJazzContext());
|
8
|
-
#update = () => { };
|
9
|
-
#Schema;
|
10
|
-
#options;
|
6
|
+
#ctx = getJazzContext();
|
11
7
|
#id;
|
12
|
-
#
|
8
|
+
#subscribe;
|
13
9
|
constructor(Schema, id, options) {
|
14
|
-
this.#
|
15
|
-
this.#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
this.#id = $derived.by(typeof id === 'function' ? id : () => id);
|
11
|
+
this.#subscribe = $derived.by(() => {
|
12
|
+
const ctx = this.#ctx.current;
|
13
|
+
const id = this.#id;
|
14
|
+
if (!ctx || !id)
|
15
|
+
return;
|
16
|
+
const agent = 'me' in ctx ? ctx.me : ctx.guest;
|
17
|
+
return createSubscriber(update => {
|
18
|
+
const unsubscribe = subscribeToCoValue(anySchemaToCoSchema(Schema), id, {
|
19
|
+
// @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
|
20
|
+
resolve: options?.resolve,
|
21
|
+
loadAs: agent,
|
22
|
+
onUnavailable: () => {
|
23
|
+
this.#value = null;
|
24
|
+
update();
|
25
|
+
},
|
26
|
+
onUnauthorized: () => {
|
27
|
+
this.#value = null;
|
28
|
+
update();
|
29
|
+
},
|
30
|
+
syncResolution: true
|
31
|
+
}, value => {
|
32
|
+
if (value === this.#value)
|
33
|
+
return;
|
34
|
+
this.#value = value;
|
35
|
+
update();
|
36
|
+
});
|
37
|
+
return () => {
|
38
|
+
unsubscribe();
|
39
|
+
this.#value = undefined;
|
40
|
+
};
|
23
41
|
});
|
24
|
-
return () => {
|
25
|
-
this.#unsubscribe();
|
26
|
-
};
|
27
42
|
});
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
// Reset state when dependencies change
|
33
|
-
this.updateValue(undefined);
|
34
|
-
this.#unsubscribe();
|
35
|
-
if (!ctx.current || !id)
|
36
|
-
return;
|
37
|
-
const agent = "me" in ctx.current ? ctx.current.me : ctx.current.guest;
|
38
|
-
// Setup subscription with current values
|
39
|
-
this.#unsubscribe = subscribeToCoValue(anySchemaToCoSchema(this.#Schema), id, {
|
40
|
-
// @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
|
41
|
-
resolve: this.#options?.resolve,
|
42
|
-
loadAs: agent,
|
43
|
-
onUnavailable: () => {
|
44
|
-
this.updateValue(null);
|
45
|
-
},
|
46
|
-
onUnauthorized: () => {
|
47
|
-
this.updateValue(null);
|
48
|
-
},
|
49
|
-
syncResolution: true,
|
50
|
-
}, (value) => {
|
51
|
-
this.updateValue(value);
|
43
|
+
$effect.pre(() => {
|
44
|
+
if (!this.#id || !this.#ctx.current)
|
45
|
+
return;
|
46
|
+
this.#subscribe?.();
|
52
47
|
});
|
53
48
|
}
|
54
|
-
updateValue(value) {
|
55
|
-
if (value !== this.#value) {
|
56
|
-
this.#value = value;
|
57
|
-
this.#update();
|
58
|
-
}
|
59
|
-
}
|
60
49
|
get current() {
|
61
|
-
this.#subscribe();
|
50
|
+
this.#subscribe?.();
|
62
51
|
return this.#value;
|
63
52
|
}
|
64
53
|
}
|
65
54
|
export class AccountCoState {
|
66
55
|
#value = undefined;
|
56
|
+
#ctx = getJazzContext();
|
67
57
|
#subscribe;
|
68
|
-
#ctx = $derived(getJazzContext());
|
69
|
-
#Schema;
|
70
|
-
#update = () => { };
|
71
|
-
#unsubscribe = () => { };
|
72
|
-
#options;
|
73
58
|
constructor(Schema, options) {
|
74
|
-
this.#
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
59
|
+
this.#subscribe = $derived.by(() => {
|
60
|
+
const ctx = this.#ctx.current;
|
61
|
+
if (!ctx || !('me' in ctx))
|
62
|
+
return;
|
63
|
+
const me = ctx.me;
|
64
|
+
return createSubscriber(update => {
|
65
|
+
// Setup subscription with current values
|
66
|
+
const unsubscribe = subscribeToCoValue(anySchemaToCoSchema(Schema), me.id, {
|
67
|
+
// @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
|
68
|
+
resolve: options?.resolve,
|
69
|
+
loadAs: me,
|
70
|
+
onUnavailable: () => {
|
71
|
+
this.#value = null;
|
72
|
+
update();
|
73
|
+
},
|
74
|
+
onUnauthorized: () => {
|
75
|
+
this.#value = null;
|
76
|
+
update();
|
77
|
+
},
|
78
|
+
syncResolution: true
|
79
|
+
}, value => {
|
80
|
+
if (value === this.#value)
|
81
|
+
return;
|
82
|
+
this.#value = value;
|
83
|
+
update();
|
84
|
+
});
|
85
|
+
return () => {
|
86
|
+
unsubscribe();
|
87
|
+
this.#value = undefined;
|
88
|
+
};
|
81
89
|
});
|
82
|
-
return () => {
|
83
|
-
this.#unsubscribe();
|
84
|
-
};
|
85
90
|
});
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
this.updateValue(undefined);
|
91
|
-
this.#unsubscribe();
|
92
|
-
if (!ctx.current)
|
93
|
-
return;
|
94
|
-
if (!("me" in ctx.current))
|
95
|
-
return;
|
96
|
-
const me = ctx.current.me;
|
97
|
-
// Setup subscription with current values
|
98
|
-
this.#unsubscribe = subscribeToCoValue(anySchemaToCoSchema(this.#Schema), me.id, {
|
99
|
-
// @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
|
100
|
-
resolve: this.#options?.resolve,
|
101
|
-
loadAs: me,
|
102
|
-
onUnavailable: () => {
|
103
|
-
this.updateValue(null);
|
104
|
-
},
|
105
|
-
onUnauthorized: () => {
|
106
|
-
this.updateValue(null);
|
107
|
-
},
|
108
|
-
syncResolution: true,
|
109
|
-
}, (value) => {
|
110
|
-
this.updateValue(value);
|
91
|
+
$effect.pre(() => {
|
92
|
+
if (!this.#ctx.current)
|
93
|
+
return;
|
94
|
+
this.#subscribe?.();
|
111
95
|
});
|
112
96
|
}
|
113
97
|
logOut = () => {
|
114
98
|
this.#ctx.current?.logOut();
|
115
99
|
};
|
116
|
-
updateValue(value) {
|
117
|
-
if (value !== this.#value) {
|
118
|
-
this.#value = value;
|
119
|
-
this.#update();
|
120
|
-
}
|
121
|
-
}
|
122
100
|
get current() {
|
123
|
-
this.#subscribe();
|
101
|
+
this.#subscribe?.();
|
124
102
|
return this.#value;
|
125
103
|
}
|
126
104
|
get agent() {
|
127
105
|
if (!this.#ctx.current) {
|
128
|
-
throw new Error(
|
106
|
+
throw new Error('No context found');
|
129
107
|
}
|
130
|
-
return
|
108
|
+
return 'me' in this.#ctx.current ? this.#ctx.current.me : this.#ctx.current.guest;
|
131
109
|
}
|
132
110
|
}
|
@@ -9,6 +9,8 @@
|
|
9
9
|
dog: true
|
10
10
|
}
|
11
11
|
})
|
12
|
+
|
13
|
+
const dogName = $derived(person.current!.dog.name);
|
12
14
|
</script>
|
13
15
|
|
14
16
|
<!-- Using non-null assertions because we want to test that locally available values are never null -->
|
@@ -27,4 +29,4 @@
|
|
27
29
|
</label>
|
28
30
|
|
29
31
|
<div data-testid="person-name">{person.current!.name}</div>
|
30
|
-
<div data-testid="person-dog-name">{
|
32
|
+
<div data-testid="person-dog-name">{dogName}</div>
|
@@ -10,18 +10,24 @@
|
|
10
10
|
}
|
11
11
|
}
|
12
12
|
});
|
13
|
+
|
14
|
+
const dogName = $derived(me.current!.root.dog.name);
|
13
15
|
</script>
|
14
16
|
|
15
17
|
<!-- Using non-null assertions because we want to test that locally available values are never null -->
|
16
18
|
<label>
|
17
19
|
Name
|
20
|
+
<!-- Jazz values are reactive, but they are not recognized as reactive by Svelte -->
|
21
|
+
<!-- svelte-ignore binding_property_non_reactive -->
|
18
22
|
<input type="text" bind:value={me.current!.root.name} />
|
19
23
|
</label>
|
20
24
|
|
21
25
|
<label>
|
22
26
|
Dog
|
27
|
+
<!-- Jazz values are reactive, but they are not recognized as reactive by Svelte -->
|
28
|
+
<!-- svelte-ignore binding_property_non_reactive -->
|
23
29
|
<input type="text" bind:value={me.current!.root.dog.name} />
|
24
30
|
</label>
|
25
31
|
|
26
32
|
<div data-testid="person-name">{me.current!.root.name}</div>
|
27
|
-
<div data-testid="person-dog-name">{
|
33
|
+
<div data-testid="person-dog-name">{dogName}</div>
|
@@ -1,18 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
$$bindings?: Bindings;
|
4
|
-
} & Exports;
|
5
|
-
(internal: unknown, props: {
|
6
|
-
$$events?: Events;
|
7
|
-
$$slots?: Slots;
|
8
|
-
}): Exports & {
|
9
|
-
$set?: any;
|
10
|
-
$on?: any;
|
11
|
-
};
|
12
|
-
z_$$bindings?: Bindings;
|
13
|
-
}
|
14
|
-
declare const UpdateNestedValueAccount: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
15
|
-
[evt: string]: CustomEvent<any>;
|
16
|
-
}, {}, {}, string>;
|
17
|
-
type UpdateNestedValueAccount = InstanceType<typeof UpdateNestedValueAccount>;
|
1
|
+
declare const UpdateNestedValueAccount: import("svelte").Component<Record<string, never>, {}, "">;
|
2
|
+
type UpdateNestedValueAccount = ReturnType<typeof UpdateNestedValueAccount>;
|
18
3
|
export default UpdateNestedValueAccount;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-svelte",
|
3
|
-
"version": "0.14.
|
3
|
+
"version": "0.14.21",
|
4
4
|
"files": [
|
5
5
|
"dist",
|
6
6
|
"!dist/**/*.test.*",
|
@@ -42,16 +42,16 @@
|
|
42
42
|
"prettier": "^3.3.2",
|
43
43
|
"prettier-plugin-svelte": "^3.2.6",
|
44
44
|
"publint": "^0.2.0",
|
45
|
-
"svelte": "^5.
|
45
|
+
"svelte": "^5.33.0",
|
46
46
|
"svelte-check": "^4.0.0",
|
47
47
|
"typescript": "5.6.2",
|
48
48
|
"typescript-eslint": "^8.0.0",
|
49
49
|
"vite": "6.3.5"
|
50
50
|
},
|
51
51
|
"dependencies": {
|
52
|
-
"cojson": "0.14.
|
53
|
-
"jazz-browser": "0.14.
|
54
|
-
"jazz-tools": "0.14.
|
52
|
+
"cojson": "0.14.21",
|
53
|
+
"jazz-browser": "0.14.21",
|
54
|
+
"jazz-tools": "0.14.21"
|
55
55
|
},
|
56
56
|
"scripts": {
|
57
57
|
"dev": "vite dev",
|