Skip to content

Commit

Permalink
style(json-crdt-extensions): 💄 run Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed May 8, 2024
1 parent 5e7fa89 commit 91e6a92
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 34 deletions.
12 changes: 8 additions & 4 deletions src/json-crdt-extensions/peritext/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import {ModelWithExt, ext} from '../../ModelWithExt';
export type Schema = ReturnType<typeof schema>;
export type Kit = ReturnType<typeof setupKit>;

const schema = (text: string) => s.obj({
text: ext.peritext.new(text),
});
const schema = (text: string) =>
s.obj({
text: ext.peritext.new(text),
});

export const setupKit = (initialText: string = '', edits: (model: Model<SchemaToJsonNode<Schema>>) => void = () => {}) => {
export const setupKit = (
initialText: string = '',
edits: (model: Model<SchemaToJsonNode<Schema>>) => void = () => {},
) => {
const model = ModelWithExt.create(schema(initialText));
edits(model);
const api = model.api;
Expand Down
8 changes: 4 additions & 4 deletions src/json-crdt-extensions/peritext/overlay/Overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Overlay<T = string> implements Printable, Stateful {

constructor(protected readonly txt: Peritext<T>) {
const id = txt.str.id;
this.START = this.point(id, Anchor.After)
this.START = this.point(id, Anchor.After);
this.END = this.point(id, Anchor.Before);
}

Expand Down Expand Up @@ -200,7 +200,7 @@ export class Overlay<T = string> implements Printable, Stateful {
if (isEmpty) {
const u = undefined;
let closed = false;
return () => (closed ? u : (closed = true, [u, u]));
return () => (closed ? u : ((closed = true), [u, u]));
}
let p1: OverlayPoint<T> | undefined;
let p2: OverlayPoint<T> | undefined = after;
Expand All @@ -222,15 +222,15 @@ export class Overlay<T = string> implements Printable, Stateful {
p2 = iterator();
}
}
return (p1 || p2) ? [p1, p2] : undefined;
return p1 || p2 ? [p1, p2] : undefined;
};
}

public pairs(after?: undefined | OverlayPoint<T>): IterableIterator<OverlayPair<T>> {
return new UndefEndIter(this.pairs0(after));
}

public tuples0(after: undefined | OverlayPoint<T>): UndefIterator<OverlayTuple<T>> {
public tuples0(after: undefined | OverlayPoint<T>): UndefIterator<OverlayTuple<T>> {
const iterator = this.pairs0(after);
return () => {
const pair = iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ const runPairsTests = (setup: () => Kit) => {
const overlay = peritext.overlay;
overlay.refresh();
const pairs = [...overlay.pairs()];
expect(pairs).toEqual([
[undefined, undefined]
]);
expect(pairs).toEqual([[undefined, undefined]]);
});

test('when caret at abs start, returns one pair', () => {
Expand All @@ -24,9 +22,7 @@ const runPairsTests = (setup: () => Kit) => {
const pairs = [...overlay.pairs()];
const p1 = overlay.first()!;
expect(peritext.editor.cursor.start.rightChar()?.view()).toBe('0');
expect(pairs).toEqual([
[p1, undefined]
]);
expect(pairs).toEqual([[p1, undefined]]);
});

test('when caret at abs end, returns one pair', () => {
Expand All @@ -37,9 +33,7 @@ const runPairsTests = (setup: () => Kit) => {
const pairs = [...overlay.pairs()];
const p1 = overlay.first()!;
expect(peritext.editor.cursor.start.leftChar()?.view()).toBe('9');
expect(pairs).toEqual([
[undefined, p1]
]);
expect(pairs).toEqual([[undefined, p1]]);
});

test('for only caret in overlay, returns two edge pairs', () => {
Expand Down Expand Up @@ -142,9 +136,7 @@ const runPairsTests = (setup: () => Kit) => {
overlay.refresh();
const first = overlay.first()!;
const pairs = [...overlay.pairs(first)];
expect(pairs).toEqual([
[first, undefined],
]);
expect(pairs).toEqual([[first, undefined]]);
});

test('in empty overlay, after selection start returns the selection and the edge', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('.points()', () => {
expect(overlay.first()).not.toBe(undefined);
expect(points.length).toBe(3);
});

test('iterates through all points, when points anchored to the same anchor', () => {
const {peritext, overlay} = setupWithOverlay();
peritext.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ const runPairsTests = (setup: () => Kit) => {
const overlay = peritext.overlay;
overlay.refresh();
const list = [...overlay.tuples()];
expect(list).toEqual([
[overlay.START, overlay.END],
]);
expect(list).toEqual([[overlay.START, overlay.END]]);
});

test('when caret at abs start, returns one [p, END] tuple', () => {
Expand All @@ -24,9 +22,7 @@ const runPairsTests = (setup: () => Kit) => {
const list = [...overlay.tuples()];
const p1 = overlay.first()!;
expect(peritext.editor.cursor.start.rightChar()?.view()).toBe(peritext.strApi().view()[0]);
expect(list).toEqual([
[p1, overlay.END],
]);
expect(list).toEqual([[p1, overlay.END]]);
});

test('when caret at abs end, returns one [START, p] tuple', () => {
Expand All @@ -37,9 +33,7 @@ const runPairsTests = (setup: () => Kit) => {
const list = [...overlay.tuples()];
const p1 = overlay.first()!;
expect(peritext.editor.cursor.start.leftChar()?.view()).toBe(peritext.strApi().view().slice(-1));
expect(list).toEqual([
[overlay.START, p1]
]);
expect(list).toEqual([[overlay.START, p1]]);
});

test('for only caret in overlay, returns two edge tuples', () => {
Expand Down Expand Up @@ -139,9 +133,7 @@ const runPairsTests = (setup: () => Kit) => {
overlay.refresh();
const first = overlay.first()!;
const pairs = [...overlay.tuples(first)];
expect(pairs).toEqual([
[first, overlay.END],
]);
expect(pairs).toEqual([[first, overlay.END]]);
});

test('in empty overlay, after selection start returns the selection and the edge', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-extensions/peritext/overlay/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {OverlayPoint} from "./OverlayPoint";
import type {OverlayPoint} from './OverlayPoint';

export type BlockTag = [
/**
Expand Down

0 comments on commit 91e6a92

Please sign in to comment.