jazz-tools 0.7.0-alpha.35 → 0.7.0-alpha.36
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +12 -0
- package/dist/coValues/account.js +5 -4
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +2 -1
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +6 -4
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +2 -2
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +1 -1
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +1 -1
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +16 -9
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/devtoolsFormatters.js +113 -0
- package/dist/implementation/devtoolsFormatters.js.map +1 -0
- package/dist/implementation/refs.js +24 -4
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +14 -1
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/package.json +3 -3
- package/src/coValues/account.ts +5 -4
- package/src/coValues/coList.ts +11 -8
- package/src/coValues/coMap.ts +12 -4
- package/src/coValues/coStream.ts +2 -2
- package/src/coValues/extensions/imageDef.ts +1 -1
- package/src/coValues/group.ts +1 -1
- package/src/coValues/interfaces.ts +33 -20
- package/src/implementation/devtoolsFormatters.ts +109 -0
- package/src/implementation/refs.ts +22 -4
- package/src/implementation/subscriptionScope.ts +17 -1
- package/src/internal.ts +3 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/implementation/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUhC,OAAO,EACH,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,QAAQ,GAAG,IAAI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,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,wBAAwB,CAAC,MAAM,EAAE,GAAG;YAChC,MAAM,EAAE,GAAG,WAAW,CAAC,GAAW,CAAC,CAAC;YACpC,IAAI,EAAE,EAAE,CAAC;gBACL,OAAO;oBACH,UAAU,EAAE,IAAI;oBAChB,YAAY,EAAE,IAAI;oBAClB,QAAQ,EAAE,IAAI;iBACjB,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
|
@@ -1,9 +1,12 @@
|
|
1
1
|
export const subscriptionsScopes = new WeakMap();
|
2
|
+
const TRACE_INVALIDATIONS = false;
|
2
3
|
export class SubscriptionScope {
|
3
4
|
constructor(root, rootSchema, onUpdate) {
|
4
5
|
this.scopeID = `scope-${Math.random().toString(36).slice(2)}`;
|
5
6
|
this.entries = new Map();
|
6
7
|
this.scheduledUpdate = false;
|
8
|
+
this.cachedValues = {};
|
9
|
+
this.parents = {};
|
7
10
|
this.rootEntry = {
|
8
11
|
state: "loaded",
|
9
12
|
value: root,
|
@@ -31,11 +34,13 @@ export class SubscriptionScope {
|
|
31
34
|
});
|
32
35
|
}
|
33
36
|
}
|
34
|
-
onRefAccessedOrSet(accessedOrSetId) {
|
37
|
+
onRefAccessedOrSet(fromId, accessedOrSetId) {
|
35
38
|
// console.log("onRefAccessedOrSet", this.scopeID, accessedOrSetId);
|
36
39
|
if (!accessedOrSetId) {
|
37
40
|
return;
|
38
41
|
}
|
42
|
+
this.parents[accessedOrSetId] = this.parents[accessedOrSetId] || new Set();
|
43
|
+
this.parents[accessedOrSetId].add(fromId);
|
39
44
|
if (!this.entries.has(accessedOrSetId)) {
|
40
45
|
const loadingEntry = {
|
41
46
|
state: "loading",
|
@@ -59,6 +64,7 @@ export class SubscriptionScope {
|
|
59
64
|
// console.log("ref update", this.scopeID, accessedOrSetId, JSON.stringify(rawUpdate))
|
60
65
|
if (!rawUpdate)
|
61
66
|
return;
|
67
|
+
this.invalidate(accessedOrSetId);
|
62
68
|
this.scheduleUpdate();
|
63
69
|
});
|
64
70
|
entry.rawUnsub = rawUnsub;
|
@@ -66,6 +72,13 @@ export class SubscriptionScope {
|
|
66
72
|
});
|
67
73
|
}
|
68
74
|
}
|
75
|
+
invalidate(id, fromChild) {
|
76
|
+
TRACE_INVALIDATIONS && console.log("invalidating", fromChild, "->", id, this.cachedValues[id]);
|
77
|
+
delete this.cachedValues[id];
|
78
|
+
for (const parent of this.parents[id] || []) {
|
79
|
+
this.invalidate(parent, id);
|
80
|
+
}
|
81
|
+
}
|
69
82
|
unsubscribeAll() {
|
70
83
|
for (const entry of this.entries.values()) {
|
71
84
|
if (entry.state === "loaded") {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"subscriptionScope.js","sourceRoot":"","sources":["../../src/implementation/subscriptionScope.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAG3C,CAAC;AAEJ,MAAM,OAAO,iBAAiB;
|
1
|
+
{"version":3,"file":"subscriptionScope.js","sourceRoot":"","sources":["../../src/implementation/subscriptionScope.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAG3C,CAAC;AAEJ,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,MAAM,OAAO,iBAAiB;IAoB1B,YACI,IAAU,EACV,UAA8C,EAC9C,QAAiC;QApBrC,YAAO,GAAW,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAEjE,YAAO,GAAG,IAAI,GAAG,EAId,CAAC;QAOJ,oBAAe,GAAY,KAAK,CAAC;QACjC,iBAAY,GAAiC,EAAE,CAAC;QAChD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B,CAAC;YACL,CAAC,CAAC,CAAC;QACX,CAAC;IACL,CAAC;IAED,UAAU,CAAC,EAAe,EAAE,SAAuB;QAC/C,mBAAmB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAC7B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAChC,CAAC;IACL,CAAC;IAED,cAAc;QACV,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,IAAI,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC3B,KAAK,CAAC,QAAQ,EAAE,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACJ,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAClC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACJ"}
|
package/dist/internal.js
CHANGED
@@ -11,4 +11,5 @@ export * from "./implementation/refs.js";
|
|
11
11
|
export * from "./implementation/schema.js";
|
12
12
|
export * from "./implementation/subscriptionScope.js";
|
13
13
|
export * from "./coValues/extensions/imageDef.js";
|
14
|
+
import "./implementation/devtoolsFormatters.js";
|
14
15
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uCAAuC,CAAC;AAEtD,cAAc,mCAAmC,CAAC"}
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uCAAuC,CAAC;AAEtD,cAAc,mCAAmC,CAAC;AAElD,OAAO,wCAAwC,CAAA"}
|
package/package.json
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
"types": "./src/index.ts",
|
6
6
|
"type": "module",
|
7
7
|
"license": "MIT",
|
8
|
-
"version": "0.7.0-alpha.
|
8
|
+
"version": "0.7.0-alpha.36",
|
9
9
|
"dependencies": {
|
10
10
|
"@effect/schema": "^0.66.16",
|
11
11
|
"effect": "^3.1.3",
|
12
12
|
"fast-check": "^3.17.2",
|
13
|
-
"cojson": "0.7.0-alpha.
|
14
|
-
"cojson
|
13
|
+
"cojson-transport-nodejs-ws": "0.7.0-alpha.36",
|
14
|
+
"cojson": "0.7.0-alpha.36"
|
15
15
|
},
|
16
16
|
"devDependencies": {
|
17
17
|
"typescript": "^5.3.3",
|
package/src/coValues/account.ts
CHANGED
@@ -120,6 +120,7 @@ export class Account
|
|
120
120
|
enumerable: false,
|
121
121
|
},
|
122
122
|
_raw: { value: options.fromRaw, enumerable: false },
|
123
|
+
_type: { value: "Account", enumerable: false },
|
123
124
|
});
|
124
125
|
|
125
126
|
if (this.isMe) {
|
@@ -248,10 +249,10 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
|
248
249
|
get(target, key, receiver) {
|
249
250
|
if (key === "profile") {
|
250
251
|
const ref = target._refs.profile;
|
251
|
-
return ref ? ref.accessFrom(receiver) : (undefined as any);
|
252
|
+
return ref ? ref.accessFrom(receiver, "profile") : (undefined as any);
|
252
253
|
} else if (key === "root") {
|
253
254
|
const ref = target._refs.root;
|
254
|
-
return ref ? ref.accessFrom(receiver) : (undefined as any);
|
255
|
+
return ref ? ref.accessFrom(receiver, "root") : (undefined as any);
|
255
256
|
} else {
|
256
257
|
return Reflect.get(target, key, receiver);
|
257
258
|
}
|
@@ -274,13 +275,13 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
|
274
275
|
"trusting"
|
275
276
|
);
|
276
277
|
}
|
277
|
-
subscriptionsScopes.get(receiver)?.onRefAccessedOrSet(value.id);
|
278
|
+
subscriptionsScopes.get(receiver)?.onRefAccessedOrSet(target.id, value.id);
|
278
279
|
return true;
|
279
280
|
} else if (key === "root") {
|
280
281
|
if (value) {
|
281
282
|
target._raw.set("root", value.id as unknown as CoID<RawCoMap>);
|
282
283
|
}
|
283
|
-
subscriptionsScopes.get(receiver)?.onRefAccessedOrSet(value.id);
|
284
|
+
subscriptionsScopes.get(receiver)?.onRefAccessedOrSet(target.id, value.id);
|
284
285
|
return true;
|
285
286
|
} else {
|
286
287
|
return Reflect.set(target, key, value, receiver);
|
package/src/coValues/coList.ts
CHANGED
@@ -10,9 +10,8 @@ import type {
|
|
10
10
|
RefEncoded,
|
11
11
|
ClassOf,
|
12
12
|
UnavailableError,
|
13
|
-
IfCo,
|
14
13
|
UnCo,
|
15
|
-
} from "../internal.js";
|
14
|
+
RequireOptions} from "../internal.js";
|
16
15
|
import {
|
17
16
|
Account,
|
18
17
|
CoValueBase,
|
@@ -33,7 +32,7 @@ export class CoList<Item = any>
|
|
33
32
|
extends Array<Item>
|
34
33
|
implements CoValue<"CoList", RawCoList>
|
35
34
|
{
|
36
|
-
static Of<Item>(item:
|
35
|
+
static Of<Item>(item: Item): typeof CoList<Item> {
|
37
36
|
// TODO: cache superclass for item class
|
38
37
|
return class CoListOf extends CoList<Item> {
|
39
38
|
[co.items] = item;
|
@@ -51,6 +50,7 @@ export class CoList<Item = any>
|
|
51
50
|
this.prototype._type = "CoList";
|
52
51
|
}
|
53
52
|
_raw!: RawCoList;
|
53
|
+
_instanceID!: string;
|
54
54
|
|
55
55
|
/** @internal This is only a marker type and doesn't exist at runtime */
|
56
56
|
[ItemsSym]!: Item;
|
@@ -118,6 +118,8 @@ export class CoList<Item = any>
|
|
118
118
|
) {
|
119
119
|
super();
|
120
120
|
|
121
|
+
Object.defineProperty(this, "_instanceID", {value: `instance-${Math.random().toString(36).slice(2)}`, enumerable: false});
|
122
|
+
|
121
123
|
if ("owner" in options) {
|
122
124
|
this[InitValues] = {
|
123
125
|
init: options.init,
|
@@ -231,12 +233,12 @@ export class CoList<Item = any>
|
|
231
233
|
return this.toJSON();
|
232
234
|
}
|
233
235
|
|
234
|
-
subscribe!: (listener: (update: this) => void) => () => void;
|
236
|
+
subscribe!: (listener: (update: this) => void, options?: RequireOptions<this>) => () => void;
|
235
237
|
static {
|
236
238
|
this.prototype.subscribe = CoValueBase.prototype.subscribe as any;
|
237
239
|
}
|
238
240
|
|
239
|
-
subscribeEf!: () => Stream.Stream<this, "unavailable", never>;
|
241
|
+
subscribeEf!: (options?: RequireOptions<this>) => Stream.Stream<this, "unavailable", never>;
|
240
242
|
static {
|
241
243
|
this.prototype.subscribeEf = CoValueBase.prototype.subscribeEf as any;
|
242
244
|
}
|
@@ -261,12 +263,13 @@ export class CoList<Item = any>
|
|
261
263
|
V extends CoValue,
|
262
264
|
>(
|
263
265
|
this: ClassOf<V>,
|
264
|
-
id: ID<V
|
266
|
+
id: ID<V>,
|
267
|
+
options?: { require?: (value: V) => boolean | undefined }
|
265
268
|
) => Stream.Stream<V, UnavailableError, AccountCtx>;
|
266
269
|
static subscribe = CoValueBase.subscribe as unknown as <V extends CoValue>(
|
267
270
|
this: ClassOf<V>,
|
268
271
|
id: ID<V>,
|
269
|
-
options: { as: Account | Group },
|
272
|
+
options: { as: Account | Group, require?: (value: V) => boolean | undefined },
|
270
273
|
onUpdate: (value: V) => void
|
271
274
|
) => () => void;
|
272
275
|
|
@@ -329,7 +332,7 @@ const CoListProxyHandler: ProxyHandler<CoList> = {
|
|
329
332
|
rawValue as unknown as ID<CoValue>,
|
330
333
|
target._loadedAs,
|
331
334
|
itemDescriptor
|
332
|
-
).accessFrom(receiver);
|
335
|
+
).accessFrom(receiver, Number(key));
|
333
336
|
}
|
334
337
|
} else if (key === "length") {
|
335
338
|
return target._raw.entries().length;
|
package/src/coValues/coMap.ts
CHANGED
@@ -145,7 +145,10 @@ export class CoMap extends CoValueBase implements CoValue<"CoMap", RawCoMap> {
|
|
145
145
|
rawEdit.value as ID<CoValue>,
|
146
146
|
target._loadedAs,
|
147
147
|
descriptor
|
148
|
-
).accessFrom(
|
148
|
+
).accessFrom(
|
149
|
+
target,
|
150
|
+
"_edits." + key.toString() + ".value"
|
151
|
+
),
|
149
152
|
ref:
|
150
153
|
descriptor !== "json" && isRefEncoded(descriptor)
|
151
154
|
? new Ref(
|
@@ -160,7 +163,10 @@ export class CoMap extends CoValueBase implements CoValue<"CoMap", RawCoMap> {
|
|
160
163
|
rawEdit.by as ID<Account>,
|
161
164
|
target._loadedAs,
|
162
165
|
Account
|
163
|
-
).accessFrom(
|
166
|
+
).accessFrom(
|
167
|
+
target,
|
168
|
+
"_edits." + key.toString() + ".by"
|
169
|
+
),
|
164
170
|
madeAt: rawEdit.at,
|
165
171
|
};
|
166
172
|
},
|
@@ -349,7 +355,7 @@ const CoMapProxyHandler: ProxyHandler<CoMap> = {
|
|
349
355
|
raw as unknown as ID<CoValue>,
|
350
356
|
target._loadedAs,
|
351
357
|
descriptor
|
352
|
-
).accessFrom(receiver);
|
358
|
+
).accessFrom(receiver, key);
|
353
359
|
}
|
354
360
|
} else {
|
355
361
|
return undefined;
|
@@ -378,7 +384,9 @@ const CoMapProxyHandler: ProxyHandler<CoMap> = {
|
|
378
384
|
target._raw.set(key, encodeSync(descriptor.encoded)(value));
|
379
385
|
} else if (isRefEncoded(descriptor)) {
|
380
386
|
target._raw.set(key, value.id);
|
381
|
-
subscriptionsScopes
|
387
|
+
subscriptionsScopes
|
388
|
+
.get(target)
|
389
|
+
?.onRefAccessedOrSet(target.id, value.id);
|
382
390
|
}
|
383
391
|
return true;
|
384
392
|
} else {
|
package/src/coValues/coStream.ts
CHANGED
@@ -201,7 +201,7 @@ function entryFromRawEntry<Item>(
|
|
201
201
|
return decodeSync(itemField.encoded)(rawEntry.value);
|
202
202
|
} else if (isRefEncoded(itemField)) {
|
203
203
|
return this.ref?.accessFrom(
|
204
|
-
accessFrom
|
204
|
+
accessFrom, rawEntry.by + rawEntry.tx.sessionID + rawEntry.tx.txIndex + ".value"
|
205
205
|
) as NonNullable<Item> extends CoValue
|
206
206
|
? (CoValue & Item) | null
|
207
207
|
: Item;
|
@@ -232,7 +232,7 @@ function entryFromRawEntry<Item>(
|
|
232
232
|
accountID as unknown as ID<Account>,
|
233
233
|
loadedAs,
|
234
234
|
Account
|
235
|
-
)?.accessFrom(accessFrom)
|
235
|
+
)?.accessFrom(accessFrom, rawEntry.by + rawEntry.tx.sessionID + rawEntry.tx.txIndex + ".by")
|
236
236
|
);
|
237
237
|
},
|
238
238
|
madeAt: rawEntry.at,
|
@@ -25,7 +25,7 @@ export class ImageDefinition extends CoMap {
|
|
25
25
|
const resolutions = Object.keys(this).filter(
|
26
26
|
(key) =>
|
27
27
|
key.match(/^\d+x\d+$/) &&
|
28
|
-
(
|
28
|
+
((options?.maxWidth === undefined) ||
|
29
29
|
Number(key.split("x")[0]) <= options.maxWidth)
|
30
30
|
) as `${number}x${number}`[];
|
31
31
|
|
package/src/coValues/group.ts
CHANGED
@@ -157,7 +157,7 @@ export class Group extends CoValueBase implements CoValue<"Group", RawGroup> {
|
|
157
157
|
this._loadedAs,
|
158
158
|
this._schema[MembersSym]
|
159
159
|
);
|
160
|
-
const accessRef = () => ref?.accessFrom(this);
|
160
|
+
const accessRef = () => ref?.accessFrom(this, "members." + id);
|
161
161
|
|
162
162
|
return {
|
163
163
|
id: id as unknown as Everyone | ID<this[MembersSym]>,
|
@@ -44,14 +44,15 @@ export interface CoValueClass<Value extends CoValue = CoValue, Init = any> {
|
|
44
44
|
subscribe<V extends Value, Acc extends Account>(
|
45
45
|
this: ClassOf<V>,
|
46
46
|
id: ID<V>,
|
47
|
-
options: { as: Acc & Me },
|
47
|
+
options: { as: Acc & Me, require?: (value: V) => boolean | undefined },
|
48
48
|
onUpdate: (value: V) => void
|
49
49
|
): () => void;
|
50
50
|
|
51
51
|
/** @category Subscription */
|
52
52
|
subscribeEf<V extends Value>(
|
53
53
|
this: ClassOf<V>,
|
54
|
-
id: ID<V
|
54
|
+
id: ID<V>,
|
55
|
+
options?: { require?: (value: V) => boolean | undefined }
|
55
56
|
): Stream.Stream<V, UnavailableError, AccountCtx>;
|
56
57
|
}
|
57
58
|
|
@@ -64,7 +65,7 @@ export interface CoValue<Type extends string = string, Raw = any> {
|
|
64
65
|
/** @category Collaboration */
|
65
66
|
_owner: Account | Group;
|
66
67
|
/** @category Subscription & Loading */
|
67
|
-
subscribe(listener: (update: this) => void): () => void;
|
68
|
+
subscribe(listener: (update: this) => void, options?: RequireOptions<this>): () => void;
|
68
69
|
/** @category Subscription & Loading */
|
69
70
|
subscribeEf(): Stream.Stream<this, UnavailableError, never>;
|
70
71
|
/** @category Internals */
|
@@ -94,15 +95,17 @@ export class CoValueBase implements CoValue {
|
|
94
95
|
id!: ID<this>;
|
95
96
|
_type!: string;
|
96
97
|
_raw!: RawCoValue;
|
98
|
+
_instanceID!: string;
|
97
99
|
|
98
100
|
get _owner(): Account | Group {
|
99
|
-
const owner =
|
100
|
-
|
101
|
-
|
101
|
+
const owner =
|
102
|
+
this._raw.group instanceof RawAccount
|
103
|
+
? Account.fromRaw(this._raw.group)
|
104
|
+
: Group.fromRaw(this._raw.group);
|
102
105
|
|
103
106
|
const subScope = subscriptionsScopes.get(this);
|
104
107
|
if (subScope) {
|
105
|
-
subScope.onRefAccessedOrSet(owner.id);
|
108
|
+
subScope.onRefAccessedOrSet(this.id, owner.id);
|
106
109
|
subscriptionsScopes.set(owner, subScope);
|
107
110
|
}
|
108
111
|
|
@@ -114,13 +117,15 @@ export class CoValueBase implements CoValue {
|
|
114
117
|
return Account.fromNode(this._raw.core.node);
|
115
118
|
}
|
116
119
|
|
117
|
-
constructor(..._args: any) {
|
120
|
+
constructor(..._args: any) {
|
121
|
+
Object.defineProperty(this, "_instanceID", {
|
122
|
+
value: `instance-${Math.random().toString(36).slice(2)}`,
|
123
|
+
enumerable: false,
|
124
|
+
});
|
125
|
+
}
|
118
126
|
|
119
127
|
/** @category Internals */
|
120
|
-
static fromRaw<V extends CoValue>(
|
121
|
-
this: ClassOf<V>,
|
122
|
-
raw: RawCoValue
|
123
|
-
): V {
|
128
|
+
static fromRaw<V extends CoValue>(this: ClassOf<V>, raw: RawCoValue): V {
|
124
129
|
return new this({ fromRaw: raw });
|
125
130
|
}
|
126
131
|
|
@@ -155,12 +160,12 @@ export class CoValueBase implements CoValue {
|
|
155
160
|
static subscribe<V extends CoValue, Acc extends Account>(
|
156
161
|
this: ClassOf<V> & typeof CoValueBase,
|
157
162
|
id: ID<V>,
|
158
|
-
options: { as: Acc & Me },
|
163
|
+
options: { as: Acc & Me; require?: (value: V) => boolean | undefined },
|
159
164
|
onUpdate: (value: V) => void
|
160
165
|
): () => void {
|
161
166
|
void Effect.runPromise(
|
162
167
|
Effect.provideService(
|
163
|
-
this.subscribeEf(id).pipe(
|
168
|
+
this.subscribeEf(id, { require: options.require }).pipe(
|
164
169
|
Stream.run(
|
165
170
|
Sink.forEach((update) =>
|
166
171
|
Effect.sync(() => onUpdate(update))
|
@@ -178,7 +183,8 @@ export class CoValueBase implements CoValue {
|
|
178
183
|
/** @category Subscription & Loading */
|
179
184
|
static subscribeEf<V extends CoValue>(
|
180
185
|
this: ClassOf<V> & typeof CoValueBase,
|
181
|
-
id: ID<V
|
186
|
+
id: ID<V>,
|
187
|
+
options?: { require?: (value: V) => boolean | undefined }
|
182
188
|
): Stream.Stream<V, UnavailableError, AccountCtx> {
|
183
189
|
return Stream.fromEffect(this.loadEf(id)).pipe(
|
184
190
|
Stream.flatMap((value) =>
|
@@ -188,7 +194,9 @@ export class CoValueBase implements CoValue {
|
|
188
194
|
value,
|
189
195
|
this,
|
190
196
|
(update) => {
|
191
|
-
|
197
|
+
if (!options?.require || options.require(update)) {
|
198
|
+
void emit.single(update as V);
|
199
|
+
}
|
192
200
|
}
|
193
201
|
);
|
194
202
|
|
@@ -204,19 +212,20 @@ export class CoValueBase implements CoValue {
|
|
204
212
|
}
|
205
213
|
|
206
214
|
/** @category Subscription & Loading */
|
207
|
-
subscribe(listener: (update: this) => void): () => void {
|
215
|
+
subscribe(listener: (update: this) => void, options?: RequireOptions<this>): () => void {
|
208
216
|
return (this.constructor as unknown as typeof CoValueBase).subscribe(
|
209
217
|
this.id as unknown as ID<CoValue>,
|
210
|
-
{ as: this._loadedAs },
|
218
|
+
{ as: this._loadedAs, require: options?.require as any },
|
211
219
|
listener as unknown as (update: CoValue) => void
|
212
220
|
);
|
213
221
|
}
|
214
222
|
|
215
223
|
/** @category Subscription & Loading */
|
216
|
-
subscribeEf(): Stream.Stream<this, UnavailableError, never> {
|
224
|
+
subscribeEf(options?: RequireOptions<this>): Stream.Stream<this, UnavailableError, never> {
|
217
225
|
return Stream.provideService(
|
218
226
|
(this.constructor as unknown as typeof CoValueBase).subscribeEf(
|
219
|
-
this.id as unknown as ID<CoValue
|
227
|
+
this.id as unknown as ID<CoValue>,
|
228
|
+
options as any
|
220
229
|
),
|
221
230
|
AccountCtx,
|
222
231
|
this._loadedAs
|
@@ -245,3 +254,7 @@ export class CoValueBase implements CoValue {
|
|
245
254
|
return cast;
|
246
255
|
}
|
247
256
|
}
|
257
|
+
|
258
|
+
export type RequireOptions<V extends CoValue> = {
|
259
|
+
require?: (value: V) => boolean | undefined
|
260
|
+
};
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import { ItemsSym } from "./symbols.js";
|
2
|
+
|
3
|
+
(globalThis as any).devtoolsFormatters = [
|
4
|
+
{
|
5
|
+
header: (object: any) => {
|
6
|
+
if (object._type === "CoMap") {
|
7
|
+
return ["div", {}, ["span", {}, object.constructor.name]];
|
8
|
+
} else if (object._type === "CoList") {
|
9
|
+
return [
|
10
|
+
"div",
|
11
|
+
{},
|
12
|
+
[
|
13
|
+
"span",
|
14
|
+
{},
|
15
|
+
object.constructor.name + "(" + object.length + ") ",
|
16
|
+
],
|
17
|
+
];
|
18
|
+
} else if (object._type === "Account") {
|
19
|
+
return [
|
20
|
+
"div",
|
21
|
+
{},
|
22
|
+
[
|
23
|
+
"span",
|
24
|
+
{},
|
25
|
+
object.constructor.name +
|
26
|
+
"(" +
|
27
|
+
object._refs.profile.value?.name +
|
28
|
+
(object.isMe ? " ME" : "") +
|
29
|
+
")",
|
30
|
+
],
|
31
|
+
];
|
32
|
+
} else {
|
33
|
+
return null;
|
34
|
+
}
|
35
|
+
},
|
36
|
+
hasBody: function () {
|
37
|
+
return true;
|
38
|
+
},
|
39
|
+
body: function (object: any) {
|
40
|
+
if (object._type === "CoMap" || object._type === "Account") {
|
41
|
+
return [
|
42
|
+
"div",
|
43
|
+
{ style: "margin-left: 15px" },
|
44
|
+
["div", "id: ", ["object", { object: object.id }]],
|
45
|
+
...Object.entries(object).map(([k, v]) => [
|
46
|
+
"div",
|
47
|
+
{ style: "white-space: nowrap;" },
|
48
|
+
[
|
49
|
+
"span",
|
50
|
+
{ style: "font-weight: bold; opacity: 0.6" },
|
51
|
+
k,
|
52
|
+
": ",
|
53
|
+
],
|
54
|
+
["object", { object: v }],
|
55
|
+
...(typeof object._schema[k] === "function"
|
56
|
+
? v === null
|
57
|
+
? [
|
58
|
+
[
|
59
|
+
"span",
|
60
|
+
{ style: "opacity: 0.5" },
|
61
|
+
` (pending ${object._schema[k].name} `,
|
62
|
+
[
|
63
|
+
"object",
|
64
|
+
{ object: object._refs[k] },
|
65
|
+
],
|
66
|
+
")",
|
67
|
+
],
|
68
|
+
]
|
69
|
+
: []
|
70
|
+
: []),
|
71
|
+
]),
|
72
|
+
];
|
73
|
+
} else if (object._type === "CoList") {
|
74
|
+
return [
|
75
|
+
"div",
|
76
|
+
{ style: "margin-left: 15px" },
|
77
|
+
["div", "id: ", ["object", { object: object.id }]],
|
78
|
+
...(object as any[]).map((v, i) => [
|
79
|
+
"div",
|
80
|
+
{ style: "white-space: nowrap;" },
|
81
|
+
[
|
82
|
+
"span",
|
83
|
+
{ style: "font-weight: bold; opacity: 0.6" },
|
84
|
+
i,
|
85
|
+
": ",
|
86
|
+
],
|
87
|
+
["object", { object: v }],
|
88
|
+
...(typeof object._schema[ItemsSym] === "function"
|
89
|
+
? v === null
|
90
|
+
? [
|
91
|
+
[
|
92
|
+
"span",
|
93
|
+
{ style: "opacity: 0.5" },
|
94
|
+
` (pending ${object._schema[ItemsSym].name} `,
|
95
|
+
[
|
96
|
+
"object",
|
97
|
+
{ object: object._refs[i] },
|
98
|
+
],
|
99
|
+
")",
|
100
|
+
],
|
101
|
+
]
|
102
|
+
: []
|
103
|
+
: []),
|
104
|
+
]),
|
105
|
+
];
|
106
|
+
}
|
107
|
+
},
|
108
|
+
},
|
109
|
+
];
|
@@ -16,6 +16,8 @@ import {
|
|
16
16
|
|
17
17
|
const refCache = new WeakMap<RawCoValue, CoValue>();
|
18
18
|
|
19
|
+
const TRACE_ACCESSES = false;
|
20
|
+
|
19
21
|
export class Ref<out V extends CoValue> {
|
20
22
|
constructor(
|
21
23
|
readonly id: ID<V>,
|
@@ -28,7 +30,6 @@ export class Ref<out V extends CoValue> {
|
|
28
30
|
}
|
29
31
|
|
30
32
|
get value() {
|
31
|
-
// TODO: cache it for object identity!!!
|
32
33
|
const raw = this.controlledAccount._raw.core.node.getLoaded(
|
33
34
|
this.id as unknown as CoID<RawCoValue>
|
34
35
|
);
|
@@ -87,16 +88,33 @@ export class Ref<out V extends CoValue> {
|
|
87
88
|
}
|
88
89
|
}
|
89
90
|
|
90
|
-
accessFrom(fromScopeValue: CoValue): V | null {
|
91
|
+
accessFrom(fromScopeValue: CoValue, key: string | number | symbol): V | null {
|
91
92
|
const subScope = subscriptionsScopes.get(fromScopeValue);
|
92
93
|
|
93
|
-
subScope?.onRefAccessedOrSet(this.id);
|
94
|
+
subScope?.onRefAccessedOrSet(fromScopeValue.id, this.id);
|
95
|
+
TRACE_ACCESSES && console.log(subScope?.scopeID, "accessing", fromScopeValue, key, this.id);
|
94
96
|
|
95
97
|
if (this.value && subScope) {
|
96
98
|
subscriptionsScopes.set(this.value, subScope);
|
97
99
|
}
|
98
100
|
|
99
|
-
|
101
|
+
if (subScope) {
|
102
|
+
const cached = subScope.cachedValues[this.id];
|
103
|
+
if (cached) {
|
104
|
+
TRACE_ACCESSES && console.log("cached", cached);
|
105
|
+
return cached as V;
|
106
|
+
} else if (this.value !== null) {
|
107
|
+
const freshValueInstance = instantiateRefEncoded(this.schema, this.value?._raw);
|
108
|
+
TRACE_ACCESSES && console.log("freshValueInstance", freshValueInstance);
|
109
|
+
subScope.cachedValues[this.id] = freshValueInstance;
|
110
|
+
subscriptionsScopes.set(freshValueInstance, subScope);
|
111
|
+
return freshValueInstance as V;
|
112
|
+
} else {
|
113
|
+
return null
|
114
|
+
}
|
115
|
+
} else {
|
116
|
+
return this.value;
|
117
|
+
}
|
100
118
|
}
|
101
119
|
}
|
102
120
|
|