Skip to content

Commit 9148686

Browse files
committed
refactor(util): 💡 rename iterator next type and class
1 parent 0be3182 commit 9148686

File tree

8 files changed

+68
-70
lines changed

8 files changed

+68
-70
lines changed

src/json-crdt-extensions/peritext/block/Block.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {printTree} from 'tree-dump/lib/printTree';
22
import {CONST, updateJson, updateNum} from '../../../json-hash/hash';
33
import {MarkerOverlayPoint} from '../overlay/MarkerOverlayPoint';
4-
import {UndefEndIter, type UndefIterator} from '../../../util/iterator';
4+
import {UndEndIterator, type UndEndNext} from '../../../util/iterator';
55
import {Inline} from './Inline';
66
import {formatType, getTag} from '../slice/util';
77
import {Range} from '../rga/Range';
@@ -60,7 +60,7 @@ export class Block<T = string, Attr = unknown> extends Range<T> implements IBloc
6060
* Iterate through all overlay points of this block, until the next marker
6161
* (regardless if that marker is a child or not).
6262
*/
63-
public points0(withMarker: boolean = false): UndefIterator<OverlayPoint<T>> {
63+
public points0(withMarker: boolean = false): UndEndNext<OverlayPoint<T>> {
6464
const txt = this.txt;
6565
const overlay = txt.overlay;
6666
const iterator = overlay.points0(this.marker);
@@ -82,10 +82,10 @@ export class Block<T = string, Attr = unknown> extends Range<T> implements IBloc
8282
}
8383

8484
public points(withMarker?: boolean): IterableIterator<OverlayPoint<T>> {
85-
return new UndefEndIter(this.points0(withMarker));
85+
return new UndEndIterator(this.points0(withMarker));
8686
}
8787

88-
protected tuples0(): UndefIterator<OverlayTuple<T>> {
88+
protected tuples0(): UndEndNext<OverlayTuple<T>> {
8989
const overlay = this.txt.overlay;
9090
const marker = this.marker;
9191
const iterator = overlay.tuples0(marker);
@@ -103,7 +103,7 @@ export class Block<T = string, Attr = unknown> extends Range<T> implements IBloc
103103
/**
104104
* @todo Consider moving inline-related methods to {@link LeafBlock}.
105105
*/
106-
public texts0(): UndefIterator<Inline<T>> {
106+
public texts0(): UndEndNext<Inline<T>> {
107107
const txt = this.txt;
108108
const overlay = txt.overlay;
109109
const iterator = this.tuples0();
@@ -114,7 +114,7 @@ export class Block<T = string, Attr = unknown> extends Range<T> implements IBloc
114114
let isFirst = true;
115115
let next = iterator();
116116
let closed = false;
117-
const newIterator: UndefIterator<Inline<T>> = () => {
117+
const newIterator: UndEndNext<Inline<T>> = () => {
118118
if (closed) return;
119119
const pair = next;
120120
next = iterator();
@@ -146,7 +146,7 @@ export class Block<T = string, Attr = unknown> extends Range<T> implements IBloc
146146
* @todo Consider moving inline-related methods to {@link LeafBlock}.
147147
*/
148148
public texts(): IterableIterator<Inline<T>> {
149-
return new UndefEndIter(this.texts0());
149+
return new UndEndIterator(this.texts0());
150150
}
151151

152152
public text(): string {

src/json-crdt-extensions/peritext/editor/Editor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {CommonSliceType, type SliceTypeSteps, type SliceType, type SliceTypeStep
1111
import {isLetter, isPunctuation, isWhitespace, stepsEqual} from './util';
1212
import {ValueSyncStore} from '../../../util/events/sync-store';
1313
import {MarkerOverlayPoint} from '../overlay/MarkerOverlayPoint';
14-
import {UndefEndIter, type UndefIterator} from '../../../util/iterator';
14+
import {UndEndIterator, type UndEndNext} from '../../../util/iterator';
1515
import {tick, Timespan, type ITimespanStruct} from '../../../json-crdt-patch';
1616
import {CursorAnchor, SliceStacking, SliceHeaderMask, SliceHeaderShift, SliceTypeCon} from '../slice/constants';
1717
import type {Point} from '../rga/Point';
@@ -114,7 +114,7 @@ export class Editor<T = string> implements Printable {
114114
return cursor ?? this.addCursor();
115115
}
116116

117-
public cursors0(): UndefIterator<Cursor<T>> {
117+
public cursors0(): UndEndNext<Cursor<T>> {
118118
const iterator = this.txt.localSlices.iterator0();
119119
return () => {
120120
while (true) {
@@ -130,7 +130,7 @@ export class Editor<T = string> implements Printable {
130130
}
131131

132132
public cursors() {
133-
return new UndefEndIter(this.cursors0());
133+
return new UndEndIterator(this.cursors0());
134134
}
135135

136136
public forCursor(callback: (cursor: Cursor<T>) => void): void {

src/json-crdt-extensions/peritext/editor/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type {UndefIterator} from '../../../util/iterator';
1+
import type {UndEndNext} from '../../../util/iterator';
22
import type {Point} from '../rga/Point';
33
import type {Range} from '../rga/Range';
44
import type {SliceType} from '../slice';
55
import type {SliceStacking} from '../slice/constants';
66
import type {ChunkSlice} from '../util/ChunkSlice';
77

8-
export type CharIterator<T> = UndefIterator<ChunkSlice<T>>;
8+
export type CharIterator<T> = UndEndNext<ChunkSlice<T>>;
99
export type CharPredicate<T> = (char: T) => boolean;
1010

1111
export type EditorPosition<T = string> = Point<T> | number | [at: number, anchor: 0 | 1];

src/json-crdt-extensions/peritext/overlay/Overlay.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {OverlayRefSliceEnd, OverlayRefSliceStart} from './refs';
1010
import {compare, type ITimestampStruct} from '../../../json-crdt-patch/clock';
1111
import {CONST, updateNum} from '../../../json-hash/hash';
1212
import {MarkerSlice} from '../slice/MarkerSlice';
13-
import {UndefEndIter, type UndefIterator} from '../../../util/iterator';
13+
import {UndEndIterator, type UndEndNext} from '../../../util/iterator';
1414
import {SliceStacking} from '../slice/constants';
1515
import type {Point} from '../rga/Point';
1616
import type {Range} from '../rga/Range';
@@ -196,7 +196,7 @@ export class Overlay<T = string> implements Printable, Stateful {
196196
}) as Chunk<T>;
197197
}
198198

199-
public points0(after: undefined | OverlayPoint<T>, inclusive?: boolean): UndefIterator<OverlayPoint<T>> {
199+
public points0(after: undefined | OverlayPoint<T>, inclusive?: boolean): UndEndNext<OverlayPoint<T>> {
200200
let curr = after ? (inclusive ? after : next(after)) : this.first();
201201
return () => {
202202
const ret = curr;
@@ -206,7 +206,7 @@ export class Overlay<T = string> implements Printable, Stateful {
206206
}
207207

208208
public points(after?: undefined | OverlayPoint<T>, inclusive?: boolean): IterableIterator<OverlayPoint<T>> {
209-
return new UndefEndIter(this.points0(after, inclusive));
209+
return new UndEndIterator(this.points0(after, inclusive));
210210
}
211211

212212
/**
@@ -220,7 +220,7 @@ export class Overlay<T = string> implements Printable, Stateful {
220220
* @returns All marker points in the overlay, starting from the given marker
221221
* point.
222222
*/
223-
public markers0(after: undefined | MarkerOverlayPoint<T>): UndefIterator<MarkerOverlayPoint<T>> {
223+
public markers0(after: undefined | MarkerOverlayPoint<T>): UndEndNext<MarkerOverlayPoint<T>> {
224224
let curr = after ? next2(after) : first2(this.root2);
225225
return () => {
226226
const ret = curr;
@@ -229,8 +229,8 @@ export class Overlay<T = string> implements Printable, Stateful {
229229
};
230230
}
231231

232-
public markers(after?: undefined | MarkerOverlayPoint<T>): UndefEndIter<MarkerOverlayPoint<T>> {
233-
return new UndefEndIter(this.markers0(after));
232+
public markers(after?: undefined | MarkerOverlayPoint<T>): UndEndIterator<MarkerOverlayPoint<T>> {
233+
return new UndEndIterator(this.markers0(after));
234234
}
235235

236236
/**
@@ -242,7 +242,7 @@ export class Overlay<T = string> implements Printable, Stateful {
242242
* @returns All marker points in the overlay, starting from the given marker
243243
* point.
244244
*/
245-
public markersFrom0(point: Point<T>): UndefIterator<MarkerOverlayPoint<T>> {
245+
public markersFrom0(point: Point<T>): UndEndNext<MarkerOverlayPoint<T>> {
246246
if (point.isAbsStart()) return this.markers0(undefined);
247247
let after = this.getOrNextLowerMarker(point);
248248
if (after && after.cmp(point) === 0) after = prev2(after);
@@ -261,7 +261,7 @@ export class Overlay<T = string> implements Printable, Stateful {
261261
* continues until the end of the overlay.
262262
* @returns Iterator that returns pairs of overlay points.
263263
*/
264-
public markerPairs0(start: Point<T>, end?: Point<T>): UndefIterator<MarkerOverlayPair<T>> {
264+
public markerPairs0(start: Point<T>, end?: Point<T>): UndEndNext<MarkerOverlayPair<T>> {
265265
const i = this.markersFrom0(start);
266266
let closed = false;
267267
let p1: MarkerOverlayPoint<T> | undefined;
@@ -293,7 +293,7 @@ export class Overlay<T = string> implements Printable, Stateful {
293293
};
294294
}
295295

296-
public pairs0(after: undefined | OverlayPoint<T>): UndefIterator<OverlayPair<T>> {
296+
public pairs0(after: undefined | OverlayPoint<T>): UndEndNext<OverlayPair<T>> {
297297
const isEmpty = !this.root;
298298
if (isEmpty) {
299299
const u = undefined;
@@ -325,10 +325,10 @@ export class Overlay<T = string> implements Printable, Stateful {
325325
}
326326

327327
public pairs(after?: undefined | OverlayPoint<T>): IterableIterator<OverlayPair<T>> {
328-
return new UndefEndIter(this.pairs0(after));
328+
return new UndEndIterator(this.pairs0(after));
329329
}
330330

331-
public tuples0(after: undefined | OverlayPoint<T>): UndefIterator<OverlayTuple<T>> {
331+
public tuples0(after: undefined | OverlayPoint<T>): UndEndNext<OverlayTuple<T>> {
332332
const iterator = this.pairs0(after);
333333
return () => {
334334
const pair = iterator();
@@ -340,7 +340,7 @@ export class Overlay<T = string> implements Printable, Stateful {
340340
}
341341

342342
public tuples(after?: undefined | OverlayPoint<T>): IterableIterator<OverlayTuple<T>> {
343-
return new UndefEndIter(this.tuples0(after));
343+
return new UndEndIterator(this.tuples0(after));
344344
}
345345

346346
/**

0 commit comments

Comments
 (0)