From 3ccba743dfa584beb0e1de2977a19777feeecb64 Mon Sep 17 00:00:00 2001 From: Va Da Date: Sun, 27 Oct 2024 11:59:27 +0000 Subject: [PATCH] =?UTF-8?q?feat(json-crdt-patch):=20=F0=9F=8E=B8=20impleme?= =?UTF-8?q?nt=20toCompact()=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-patch/clock/__tests__/clock.spec.ts | 4 ++++ src/json-crdt-patch/clock/clock.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/json-crdt-patch/clock/__tests__/clock.spec.ts b/src/json-crdt-patch/clock/__tests__/clock.spec.ts index d5a998ca44..2b54876ea5 100644 --- a/src/json-crdt-patch/clock/__tests__/clock.spec.ts +++ b/src/json-crdt-patch/clock/__tests__/clock.spec.ts @@ -54,3 +54,7 @@ test('forking clones all clocks in vector', () => { expect(cloned.peers.get(4)!.time).toBe(2); expect(cloned.peers.get(5)!.time).toBe(4); }); + +test('', () => { + +}); diff --git a/src/json-crdt-patch/clock/clock.ts b/src/json-crdt-patch/clock/clock.ts index 998f96acca..ba751c0ec9 100644 --- a/src/json-crdt-patch/clock/clock.ts +++ b/src/json-crdt-patch/clock/clock.ts @@ -202,6 +202,14 @@ export class ClockVector extends LogicalClock implements IClockVector { return clock; } + public toCompact(): number[] { + const result: number[] = [this.sid, this.time - 1]; + this.peers.forEach(ts => { + result.push(ts.sid, ts.time); + }); + return result; + } + /** * Returns a human-readable string representation of the clock vector. *