@cuboapp/crdt 1.0.25 → 1.0.27
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/package.json +1 -1
- package/src/client/index.ts +9 -11
- package/src/client/types/index.ts +0 -2
package/package.json
CHANGED
package/src/client/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { keyBy, pick, uuid } from '@cuboapp/utils'
|
|
2
2
|
import { WsClientEvent } from '@cuboapp/ws'
|
|
3
|
-
import { computed, reactive } from 'vue'
|
|
3
|
+
import { computed, reactive, shallowReactive } from 'vue'
|
|
4
4
|
import { applyAwarenessUpdate, Awareness, encodeAwarenessUpdate, removeAwarenessStates } from 'y-protocols/awareness'
|
|
5
5
|
import { applyUpdate, Doc } from 'yjs'
|
|
6
6
|
|
|
@@ -27,7 +27,7 @@ export class CuboCrdtClient<M> {
|
|
|
27
27
|
public store: CuboCrdtClientStore<M> = {}
|
|
28
28
|
// Реактивен только реестр: Vue отслеживает set/delete и повторно вычисляет
|
|
29
29
|
// computed(useDoc). Сами Y.Doc/Awareness остаются исходными объектами без proxy.
|
|
30
|
-
public docs = new Map<string, CuboCrdtClientDoc>()
|
|
30
|
+
public docs = shallowReactive(new Map<string, CuboCrdtClientDoc>())
|
|
31
31
|
|
|
32
32
|
private listeners: Map<string, Map<string, (ctx: CuboCrdtClientSubscribeEvent) => void | Promise<void>>> = new Map()
|
|
33
33
|
|
|
@@ -351,7 +351,7 @@ export class CuboCrdtClient<M> {
|
|
|
351
351
|
|
|
352
352
|
const item = this.store[storeKey]
|
|
353
353
|
item?.state.rows.forEach((row) => {
|
|
354
|
-
this.detachDocument(`${entity}`, (row as any).id, subscribe_id
|
|
354
|
+
this.detachDocument(`${entity}`, (row as any).id, subscribe_id)
|
|
355
355
|
})
|
|
356
356
|
|
|
357
357
|
// очищаем стор
|
|
@@ -425,15 +425,13 @@ export class CuboCrdtClient<M> {
|
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
public update<K extends string
|
|
428
|
+
public update<K extends Extract<keyof M, string>>(
|
|
429
429
|
entity: K,
|
|
430
430
|
entity_id: number,
|
|
431
431
|
dto: K extends Extract<keyof M, string> ? Partial<M[K]> : object,
|
|
432
432
|
opts?: CuboCrdtClientDocOrigin
|
|
433
433
|
) {
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
const document = this.docs.get(storeKey)
|
|
434
|
+
const document = this.docs.get(`${entity}:${entity_id}`)
|
|
437
435
|
|
|
438
436
|
if (document) {
|
|
439
437
|
const map = document.doc.getMap()
|
|
@@ -549,7 +547,7 @@ export class CuboCrdtClient<M> {
|
|
|
549
547
|
}
|
|
550
548
|
}
|
|
551
549
|
|
|
552
|
-
private detachDocument(entity: string, entity_id: number, subscribe_id: string
|
|
550
|
+
private detachDocument(entity: string, entity_id: number, subscribe_id: string) {
|
|
553
551
|
const key = `${entity}:${entity_id}`
|
|
554
552
|
const document = this.docs.get(key)
|
|
555
553
|
if (!document) {
|
|
@@ -622,11 +620,11 @@ export class CuboCrdtClient<M> {
|
|
|
622
620
|
|
|
623
621
|
applyUpdate(yjsDoc, update, { react: false })
|
|
624
622
|
|
|
625
|
-
const document
|
|
623
|
+
const document = shallowReactive<CuboCrdtClientDoc>({
|
|
626
624
|
doc: yjsDoc,
|
|
627
625
|
subscribes: new Set(),
|
|
628
626
|
awarenessSubscribes: new Set()
|
|
629
|
-
}
|
|
627
|
+
})
|
|
630
628
|
this.attachDocument(ctx.entity, entity_id, document, opts)
|
|
631
629
|
// Публикуем контейнер реактивному реестру только после полной инициализации.
|
|
632
630
|
// Тогда первый computed(useDoc) не увидит промежуточный doc без Awareness.
|
|
@@ -787,7 +785,7 @@ export class CuboCrdtClient<M> {
|
|
|
787
785
|
continue
|
|
788
786
|
}
|
|
789
787
|
|
|
790
|
-
this.detachDocument(ctx.entity, entity_id, opts.subscribe_id
|
|
788
|
+
this.detachDocument(ctx.entity, entity_id, opts.subscribe_id)
|
|
791
789
|
}
|
|
792
790
|
|
|
793
791
|
const rowsById = new Map(item.state.rows.map((row: any) => [Number(row.id), row]))
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type WsClient } from '@cuboapp/ws'
|
|
2
2
|
import { ComputedRef } from 'vue'
|
|
3
|
-
import { Awareness } from 'y-protocols/awareness'
|
|
4
3
|
|
|
5
4
|
import { CuboCrdtAction, CuboCrdtListSyncData, CuboCrdtListTotals, CuboCrdtSubscriptionStatus } from '../../types'
|
|
6
5
|
|
|
@@ -39,7 +38,6 @@ export type CuboCrdtClientSubscribeEvent = {
|
|
|
39
38
|
export type CuboCrdtClientList<T> = {
|
|
40
39
|
subscribe_id: string
|
|
41
40
|
storeKey: string
|
|
42
|
-
awarenesses?: ComputedRef<Map<number, Awareness> | undefined>
|
|
43
41
|
subscribe: (filters?: any) => void
|
|
44
42
|
upgrade: (filters?: any) => void
|
|
45
43
|
unsubscribe: (clear?: boolean) => void
|