jazz-tools 0.8.15 → 0.8.16
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +276 -269
- package/dist/native/coValues/account.js +3 -6
- package/dist/native/coValues/account.js.map +1 -1
- package/dist/native/coValues/coList.js +3 -7
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coMap.js +8 -14
- package/dist/native/coValues/coMap.js.map +1 -1
- package/dist/native/coValues/coStream.js +7 -12
- package/dist/native/coValues/coStream.js.map +1 -1
- package/dist/native/coValues/deepLoading.js +6 -3
- package/dist/native/coValues/deepLoading.js.map +1 -1
- package/dist/native/coValues/extensions/imageDef.js.map +1 -1
- package/dist/native/coValues/group.js +3 -6
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/coValues/interfaces.js +4 -3
- package/dist/native/coValues/interfaces.js.map +1 -1
- package/dist/native/exports.js +3 -9
- package/dist/native/exports.js.map +1 -1
- package/dist/native/implementation/createContext.js +1 -2
- package/dist/native/implementation/createContext.js.map +1 -1
- package/dist/native/implementation/devtoolsFormatters.js +5 -25
- package/dist/native/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/native/implementation/refs.js +1 -2
- package/dist/native/implementation/refs.js.map +1 -1
- package/dist/native/implementation/schema.js +1 -1
- package/dist/native/implementation/schema.js.map +1 -1
- package/dist/native/implementation/subscriptionScope.js +2 -4
- package/dist/native/implementation/subscriptionScope.js.map +1 -1
- package/dist/native/index.native.js +1 -1
- package/dist/native/index.native.js.map +1 -1
- package/dist/native/lib/cache.js.map +1 -1
- package/dist/native/lib/cache.test.js +1 -1
- package/dist/native/lib/cache.test.js.map +1 -1
- package/dist/web/coValues/account.js +3 -6
- package/dist/web/coValues/account.js.map +1 -1
- package/dist/web/coValues/coList.js +3 -7
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coMap.js +8 -14
- package/dist/web/coValues/coMap.js.map +1 -1
- package/dist/web/coValues/coStream.js +7 -12
- package/dist/web/coValues/coStream.js.map +1 -1
- package/dist/web/coValues/deepLoading.js +6 -3
- package/dist/web/coValues/deepLoading.js.map +1 -1
- package/dist/web/coValues/extensions/imageDef.js.map +1 -1
- package/dist/web/coValues/group.js +3 -6
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/coValues/interfaces.js +4 -3
- package/dist/web/coValues/interfaces.js.map +1 -1
- package/dist/web/exports.js +3 -9
- package/dist/web/exports.js.map +1 -1
- package/dist/web/implementation/createContext.js +1 -2
- package/dist/web/implementation/createContext.js.map +1 -1
- package/dist/web/implementation/devtoolsFormatters.js +5 -25
- package/dist/web/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/web/implementation/refs.js +1 -2
- package/dist/web/implementation/refs.js.map +1 -1
- package/dist/web/implementation/schema.js +1 -1
- package/dist/web/implementation/schema.js.map +1 -1
- package/dist/web/implementation/subscriptionScope.js +2 -4
- package/dist/web/implementation/subscriptionScope.js.map +1 -1
- package/dist/web/lib/cache.js.map +1 -1
- package/dist/web/lib/cache.test.js +1 -1
- package/dist/web/lib/cache.test.js.map +1 -1
- package/package.json +5 -9
- package/src/coValues/account.ts +330 -339
- package/src/coValues/coList.ts +474 -495
- package/src/coValues/coMap.ts +584 -604
- package/src/coValues/coStream.ts +624 -650
- package/src/coValues/deepLoading.ts +184 -200
- package/src/coValues/extensions/imageDef.ts +44 -44
- package/src/coValues/group.ts +196 -210
- package/src/coValues/interfaces.ts +197 -199
- package/src/exports.ts +38 -26
- package/src/implementation/createContext.ts +206 -213
- package/src/implementation/devtoolsFormatters.ts +80 -100
- package/src/implementation/refs.ts +127 -139
- package/src/implementation/schema.ts +124 -128
- package/src/implementation/subscriptionScope.ts +111 -121
- package/src/index.native.ts +3 -3
- package/src/lib/cache.test.ts +48 -48
- package/src/lib/cache.ts +9 -9
- package/src/tests/coList.test.ts +264 -283
- package/src/tests/coMap.test.ts +741 -761
- package/src/tests/coStream.test.ts +405 -438
- package/src/tests/deepLoading.test.ts +251 -256
- package/src/tests/groupsAndAccounts.test.ts +70 -74
- package/src/tests/schema.test.ts +198 -198
- package/src/tests/subscribe.test.ts +312 -299
- package/tsconfig.json +2 -4
- package/tsconfig.native.json +4 -10
- package/tsconfig.web.json +4 -10
- package/.eslintrc.cjs +0 -24
- package/.prettierrc.js +0 -9
@@ -1,182 +1,178 @@
|
|
1
1
|
import type { JsonValue, RawCoValue } from "cojson";
|
2
|
+
import { CoJsonValue } from "cojson/src/jsonValue.js";
|
2
3
|
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
type CoValue,
|
5
|
+
type CoValueClass,
|
6
|
+
CoValueFromRaw,
|
7
|
+
ItemsSym,
|
8
|
+
MembersSym,
|
9
|
+
SchemaInit,
|
10
|
+
isCoValueClass,
|
10
11
|
} from "../internal.js";
|
11
|
-
import { CoJsonValue } from "cojson/src/jsonValue.js";
|
12
12
|
|
13
13
|
/** @category Schema definition */
|
14
14
|
export const Encoders = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
Date: {
|
16
|
+
encode: (value: Date) => value.toISOString(),
|
17
|
+
decode: (value: JsonValue) => new Date(value as string),
|
18
|
+
},
|
19
19
|
};
|
20
20
|
|
21
21
|
export type CoMarker = { readonly __co: unique symbol };
|
22
22
|
/** @category Schema definition */
|
23
23
|
export type co<T> = T | (T & CoMarker);
|
24
24
|
export type IfCo<C, R> = C extends infer _A | infer B
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
? B extends CoMarker
|
26
|
+
? R
|
27
|
+
: never
|
28
|
+
: never;
|
29
29
|
export type UnCo<T> = T extends co<infer A> ? A : T;
|
30
30
|
|
31
31
|
const optional = {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
32
|
+
ref: optionalRef,
|
33
|
+
json<T extends CoJsonValue<T>>(): co<T | undefined> {
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
35
|
+
return { [SchemaInit]: "json" satisfies Schema } as any;
|
36
|
+
},
|
37
|
+
encoded<T>(arg: OptionalEncoder<T>): co<T | undefined> {
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
39
|
+
return { [SchemaInit]: { encoded: arg } satisfies Schema } as any;
|
40
|
+
},
|
41
|
+
string: {
|
42
|
+
[SchemaInit]: "json" satisfies Schema,
|
43
|
+
} as unknown as co<string | undefined>,
|
44
|
+
number: {
|
45
|
+
[SchemaInit]: "json" satisfies Schema,
|
46
|
+
} as unknown as co<number | undefined>,
|
47
|
+
boolean: {
|
48
|
+
[SchemaInit]: "json" satisfies Schema,
|
49
|
+
} as unknown as co<boolean | undefined>,
|
50
|
+
null: {
|
51
|
+
[SchemaInit]: "json" satisfies Schema,
|
52
|
+
} as unknown as co<null | undefined>,
|
53
|
+
Date: {
|
54
|
+
[SchemaInit]: { encoded: Encoders.Date } satisfies Schema,
|
55
|
+
} as unknown as co<Date | undefined>,
|
56
|
+
literal<T extends (string | number | boolean)[]>(
|
57
|
+
..._lit: T
|
58
|
+
): co<T[number] | undefined> {
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
60
|
+
return { [SchemaInit]: "json" satisfies Schema } as any;
|
61
|
+
},
|
62
62
|
};
|
63
63
|
|
64
64
|
/** @category Schema definition */
|
65
65
|
export const co = {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
members: MembersSym as MembersSym,
|
98
|
-
optional,
|
66
|
+
string: {
|
67
|
+
[SchemaInit]: "json" satisfies Schema,
|
68
|
+
} as unknown as co<string>,
|
69
|
+
number: {
|
70
|
+
[SchemaInit]: "json" satisfies Schema,
|
71
|
+
} as unknown as co<number>,
|
72
|
+
boolean: {
|
73
|
+
[SchemaInit]: "json" satisfies Schema,
|
74
|
+
} as unknown as co<boolean>,
|
75
|
+
null: {
|
76
|
+
[SchemaInit]: "json" satisfies Schema,
|
77
|
+
} as unknown as co<null>,
|
78
|
+
Date: {
|
79
|
+
[SchemaInit]: { encoded: Encoders.Date } satisfies Schema,
|
80
|
+
} as unknown as co<Date>,
|
81
|
+
literal<T extends (string | number | boolean)[]>(..._lit: T): co<T[number]> {
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
83
|
+
return { [SchemaInit]: "json" satisfies Schema } as any;
|
84
|
+
},
|
85
|
+
json<T extends CoJsonValue<T>>(): co<T> {
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
87
|
+
return { [SchemaInit]: "json" satisfies Schema } as any;
|
88
|
+
},
|
89
|
+
encoded<T>(arg: Encoder<T>): co<T> {
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
91
|
+
return { [SchemaInit]: { encoded: arg } satisfies Schema } as any;
|
92
|
+
},
|
93
|
+
ref,
|
94
|
+
items: ItemsSym as ItemsSym,
|
95
|
+
members: MembersSym as MembersSym,
|
96
|
+
optional,
|
99
97
|
};
|
100
98
|
|
101
99
|
function optionalRef<C extends CoValueClass>(
|
102
|
-
|
100
|
+
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
103
101
|
): co<InstanceType<C> | null | undefined> {
|
104
|
-
|
102
|
+
return ref(arg, { optional: true });
|
105
103
|
}
|
106
104
|
|
107
105
|
function ref<C extends CoValueClass>(
|
108
|
-
|
109
|
-
|
106
|
+
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
107
|
+
options?: never,
|
110
108
|
): co<InstanceType<C> | null>;
|
111
109
|
function ref<C extends CoValueClass>(
|
112
|
-
|
113
|
-
|
110
|
+
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
111
|
+
options: { optional: true },
|
114
112
|
): co<InstanceType<C> | null | undefined>;
|
115
113
|
function ref<
|
116
|
-
|
117
|
-
|
114
|
+
C extends CoValueClass,
|
115
|
+
Options extends { optional?: boolean } | undefined,
|
118
116
|
>(
|
119
|
-
|
120
|
-
|
117
|
+
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
118
|
+
options?: Options,
|
121
119
|
): Options extends { optional: true }
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
120
|
+
? co<InstanceType<C> | null | undefined>
|
121
|
+
: co<InstanceType<C> | null> {
|
122
|
+
return {
|
123
|
+
[SchemaInit]: {
|
124
|
+
ref: arg,
|
125
|
+
optional: options?.optional || false,
|
126
|
+
} satisfies Schema,
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
128
|
+
} as any;
|
131
129
|
}
|
132
130
|
|
133
131
|
export type JsonEncoded = "json";
|
134
132
|
export type EncodedAs<V> = { encoded: Encoder<V> | OptionalEncoder<V> };
|
135
133
|
export type RefEncoded<V extends CoValue> = {
|
136
|
-
|
137
|
-
|
134
|
+
ref: CoValueClass<V> | ((raw: RawCoValue) => CoValueClass<V>);
|
135
|
+
optional: boolean;
|
138
136
|
};
|
139
137
|
|
140
138
|
export function isRefEncoded<V extends CoValue>(
|
141
|
-
|
139
|
+
schema: Schema,
|
142
140
|
): schema is RefEncoded<V> {
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
141
|
+
return (
|
142
|
+
typeof schema === "object" &&
|
143
|
+
"ref" in schema &&
|
144
|
+
"optional" in schema &&
|
145
|
+
typeof schema.ref === "function"
|
146
|
+
);
|
149
147
|
}
|
150
148
|
|
151
149
|
export function instantiateRefEncoded<V extends CoValue>(
|
152
|
-
|
153
|
-
|
150
|
+
schema: RefEncoded<V>,
|
151
|
+
raw: RawCoValue,
|
154
152
|
): V {
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
) => CoValueClass<V> & CoValueFromRaw<V>
|
161
|
-
)(raw).fromRaw(raw);
|
153
|
+
return isCoValueClass<V>(schema.ref)
|
154
|
+
? schema.ref.fromRaw(raw)
|
155
|
+
: (schema.ref as (raw: RawCoValue) => CoValueClass<V> & CoValueFromRaw<V>)(
|
156
|
+
raw,
|
157
|
+
).fromRaw(raw);
|
162
158
|
}
|
163
159
|
|
164
160
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
165
161
|
export type Schema = JsonEncoded | RefEncoded<CoValue> | EncodedAs<any>;
|
166
162
|
|
167
163
|
export type SchemaFor<Field> = NonNullable<Field> extends CoValue
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
164
|
+
? RefEncoded<NonNullable<Field>>
|
165
|
+
: NonNullable<Field> extends JsonValue
|
166
|
+
? JsonEncoded
|
167
|
+
: EncodedAs<NonNullable<Field>>;
|
172
168
|
|
173
169
|
export type Encoder<V> = {
|
174
|
-
|
175
|
-
|
176
|
-
}
|
170
|
+
encode: (value: V) => JsonValue;
|
171
|
+
decode: (value: JsonValue) => V;
|
172
|
+
};
|
177
173
|
export type OptionalEncoder<V> =
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
174
|
+
| Encoder<V>
|
175
|
+
| {
|
176
|
+
encode: (value: V | undefined) => JsonValue;
|
177
|
+
decode: (value: JsonValue) => V | undefined;
|
178
|
+
};
|
@@ -1,148 +1,138 @@
|
|
1
1
|
import type { RawCoValue } from "cojson";
|
2
2
|
import type {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
Account,
|
4
|
+
AnonymousJazzAgent,
|
5
|
+
CoValue,
|
6
|
+
CoValueClass,
|
7
|
+
CoValueFromRaw,
|
8
|
+
ID,
|
9
9
|
} from "../internal.js";
|
10
10
|
|
11
11
|
export const subscriptionsScopes = new WeakMap<
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
CoValue,
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
|
+
SubscriptionScope<any>
|
15
15
|
>();
|
16
16
|
|
17
17
|
const TRACE_INVALIDATIONS = false;
|
18
18
|
|
19
19
|
export class SubscriptionScope<Root extends CoValue> {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
scopeID: string = `scope-${Math.random().toString(36).slice(2)}`;
|
21
|
+
subscriber: Account | AnonymousJazzAgent;
|
22
|
+
entries = new Map<
|
23
|
+
ID<CoValue>,
|
24
|
+
| { state: "loading"; immediatelyUnsub?: boolean }
|
25
|
+
| { state: "loaded"; rawUnsub: () => void }
|
26
|
+
>();
|
27
|
+
rootEntry: {
|
28
|
+
state: "loaded";
|
29
|
+
value: RawCoValue;
|
30
|
+
rawUnsub: () => void;
|
31
|
+
};
|
32
|
+
scheduleUpdate: () => void;
|
33
|
+
scheduledUpdate: boolean = false;
|
34
|
+
cachedValues: { [id: ID<CoValue>]: CoValue } = {};
|
35
|
+
parents: { [id: ID<CoValue>]: Set<ID<CoValue>> } = {};
|
36
|
+
|
37
|
+
constructor(
|
38
|
+
root: Root,
|
39
|
+
rootSchema: CoValueClass<Root> & CoValueFromRaw<Root>,
|
40
|
+
onUpdate: (newRoot: Root) => void,
|
41
|
+
) {
|
42
|
+
this.rootEntry = {
|
43
|
+
state: "loaded" as const,
|
44
|
+
value: root._raw,
|
45
|
+
rawUnsub: () => {}, // placeholder
|
31
46
|
};
|
32
|
-
|
33
|
-
scheduledUpdate: boolean = false;
|
34
|
-
cachedValues: { [id: ID<CoValue>]: CoValue } = {};
|
35
|
-
parents: { [id: ID<CoValue>]: Set<ID<CoValue>> } = {};
|
47
|
+
this.entries.set(root.id, this.rootEntry);
|
36
48
|
|
37
|
-
|
38
|
-
root: Root,
|
39
|
-
rootSchema: CoValueClass<Root> & CoValueFromRaw<Root>,
|
40
|
-
onUpdate: (newRoot: Root) => void,
|
41
|
-
) {
|
42
|
-
this.rootEntry = {
|
43
|
-
state: "loaded" as const,
|
44
|
-
value: root._raw,
|
45
|
-
rawUnsub: () => {}, // placeholder
|
46
|
-
};
|
47
|
-
this.entries.set(root.id, this.rootEntry);
|
49
|
+
subscriptionsScopes.set(root, this);
|
48
50
|
|
49
|
-
|
51
|
+
this.subscriber = root._loadedAs;
|
52
|
+
this.scheduleUpdate = () => {
|
53
|
+
const value = rootSchema.fromRaw(this.rootEntry.value) as Root;
|
54
|
+
subscriptionsScopes.set(value, this);
|
55
|
+
onUpdate(value);
|
56
|
+
};
|
50
57
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
this.rootEntry.rawUnsub = root._raw.core.subscribe(
|
59
|
+
(rawUpdate: RawCoValue | undefined) => {
|
60
|
+
if (!rawUpdate) return;
|
61
|
+
this.rootEntry.value = rawUpdate;
|
62
|
+
this.scheduleUpdate();
|
63
|
+
},
|
64
|
+
);
|
65
|
+
}
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
67
|
+
onRefAccessedOrSet(
|
68
|
+
fromId: ID<CoValue>,
|
69
|
+
accessedOrSetId: ID<CoValue> | undefined,
|
70
|
+
) {
|
71
|
+
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
72
|
+
if (!accessedOrSetId) {
|
73
|
+
return;
|
65
74
|
}
|
66
75
|
|
67
|
-
|
68
|
-
|
69
|
-
accessedOrSetId: ID<CoValue> | undefined,
|
70
|
-
) {
|
71
|
-
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
72
|
-
if (!accessedOrSetId) {
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
|
76
|
-
this.parents[accessedOrSetId] =
|
77
|
-
this.parents[accessedOrSetId] || new Set();
|
78
|
-
this.parents[accessedOrSetId]!.add(fromId);
|
76
|
+
this.parents[accessedOrSetId] = this.parents[accessedOrSetId] || new Set();
|
77
|
+
this.parents[accessedOrSetId]!.add(fromId);
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
rawUnsub: () => {}, // placeholder
|
101
|
-
};
|
102
|
-
this.entries.set(accessedOrSetId, entry);
|
79
|
+
if (!this.entries.has(accessedOrSetId)) {
|
80
|
+
const loadingEntry = {
|
81
|
+
state: "loading",
|
82
|
+
immediatelyUnsub: false,
|
83
|
+
} as const;
|
84
|
+
this.entries.set(accessedOrSetId, loadingEntry);
|
85
|
+
const node =
|
86
|
+
this.subscriber._type === "Account"
|
87
|
+
? this.subscriber._raw.core.node
|
88
|
+
: this.subscriber.node;
|
89
|
+
void node.loadCoValueCore(accessedOrSetId).then((core) => {
|
90
|
+
if (loadingEntry.state === "loading" && loadingEntry.immediatelyUnsub) {
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
if (core !== "unavailable") {
|
94
|
+
const entry = {
|
95
|
+
state: "loaded" as const,
|
96
|
+
rawUnsub: () => {}, // placeholder
|
97
|
+
};
|
98
|
+
this.entries.set(accessedOrSetId, entry);
|
103
99
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
100
|
+
const rawUnsub = core.subscribe((rawUpdate) => {
|
101
|
+
// console.log("ref update", this.scopeID, accessedOrSetId, JSON.stringify(rawUpdate))
|
102
|
+
if (!rawUpdate) return;
|
103
|
+
this.invalidate(accessedOrSetId);
|
104
|
+
this.scheduleUpdate();
|
105
|
+
});
|
110
106
|
|
111
|
-
|
112
|
-
}
|
113
|
-
});
|
107
|
+
entry.rawUnsub = rawUnsub;
|
114
108
|
}
|
109
|
+
});
|
115
110
|
}
|
111
|
+
}
|
116
112
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
this.cachedValues[id],
|
130
|
-
);
|
131
|
-
delete this.cachedValues[id];
|
132
|
-
seen.add(id);
|
133
|
-
for (const parent of this.parents[id] || []) {
|
134
|
-
this.invalidate(parent, id, seen);
|
135
|
-
}
|
113
|
+
invalidate(
|
114
|
+
id: ID<CoValue>,
|
115
|
+
fromChild?: ID<CoValue>,
|
116
|
+
seen: Set<ID<CoValue>> = new Set(),
|
117
|
+
) {
|
118
|
+
if (seen.has(id)) return;
|
119
|
+
TRACE_INVALIDATIONS &&
|
120
|
+
console.log("invalidating", fromChild, "->", id, this.cachedValues[id]);
|
121
|
+
delete this.cachedValues[id];
|
122
|
+
seen.add(id);
|
123
|
+
for (const parent of this.parents[id] || []) {
|
124
|
+
this.invalidate(parent, id, seen);
|
136
125
|
}
|
126
|
+
}
|
137
127
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
}
|
146
|
-
this.entries.clear();
|
128
|
+
unsubscribeAll() {
|
129
|
+
for (const entry of this.entries.values()) {
|
130
|
+
if (entry.state === "loaded") {
|
131
|
+
entry.rawUnsub();
|
132
|
+
} else {
|
133
|
+
entry.immediatelyUnsub = true;
|
134
|
+
}
|
147
135
|
}
|
136
|
+
this.entries.clear();
|
137
|
+
}
|
148
138
|
}
|
package/src/index.native.ts
CHANGED