From bd738ad03d1c4348a7d61915173f01f6f991d989 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 7 May 2024 15:28:38 +0200 Subject: [PATCH] =?UTF-8?q?style:=20=F0=9F=92=84=20run=20Prettier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-extensions/peritext/overlay/Overlay.ts | 8 ++++++-- .../peritext/overlay/__tests__/Overlay.spec.ts | 4 ++-- src/util/iterator.ts | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/json-crdt-extensions/peritext/overlay/Overlay.ts b/src/json-crdt-extensions/peritext/overlay/Overlay.ts index 0c6ae01649..e56f4c5d6f 100644 --- a/src/json-crdt-extensions/peritext/overlay/Overlay.ts +++ b/src/json-crdt-extensions/peritext/overlay/Overlay.ts @@ -67,7 +67,7 @@ export class Overlay implements Printable, Stateful { return this.entries(); } - public splitIterator(): () => MarkerOverlayPoint | undefined { + public markerIterator(): () => MarkerOverlayPoint | undefined { let curr = this.first(); return () => { while (curr) { @@ -75,10 +75,14 @@ export class Overlay implements Printable, Stateful { if (curr) curr = next(curr); if (ret instanceof MarkerOverlayPoint) return ret; } - return undefined; + return; }; } + public markers(): IterableIterator> { + return new UndefEndIter(this.iterator()); + } + /** * Retrieve overlay point or the previous one, measured in spacial dimension. */ diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts index c1d1af857c..32d53ea071 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts @@ -21,7 +21,7 @@ const setup = () => { const markerCount = (peritext: Peritext): number => { const overlay = peritext.overlay; - const iterator = overlay.splitIterator(); + const iterator = overlay.markerIterator(); let count = 0; for (let split = iterator(); split; split = iterator()) { count++; @@ -117,7 +117,7 @@ describe('markers', () => { expect(markerCount(peritext)).toBe(2); const points = []; let point; - for (const iterator = peritext.overlay.splitIterator(); (point = iterator()); ) points.push(point); + for (const iterator = peritext.overlay.markerIterator(); (point = iterator()); ) points.push(point); expect(points.length).toBe(2); expect(points[0].pos()).toBe(2); expect(points[1].pos()).toBe(11); diff --git a/src/util/iterator.ts b/src/util/iterator.ts index 65fd4def9b..143506549d 100644 --- a/src/util/iterator.ts +++ b/src/util/iterator.ts @@ -12,5 +12,8 @@ export class UndefEndIter implements IterableIterator { } export class IterRes { - constructor(public readonly value: T, public readonly done: boolean) {} + constructor( + public readonly value: T, + public readonly done: boolean, + ) {} }