Skip to content

Commit 1852197

Browse files
authored
Merge pull request #710 from streamich/production-build
Remove usage of `constructor.name` property
2 parents 83d42ca + 3738e13 commit 1852197

File tree

27 files changed

+103
-54
lines changed

27 files changed

+103
-54
lines changed

src/json-crdt-extensions/peritext/Peritext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export class Peritext<T = string> implements Printable {
315315
const nl = () => '';
316316
const {savedSlices, extraSlices, localSlices} = this;
317317
return (
318-
this.constructor.name +
318+
'Peritext' +
319319
printTree(tab, [
320320
(tab) => this.str.toString(tab),
321321
nl,

src/json-crdt-extensions/peritext/PeritextApi.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export class PeritextApi extends NodeApi<PeritextNode> implements ExtApi<Peritex
2929

3030
public toString(tab?: string): string {
3131
return (
32-
this.constructor.name +
33-
printTree(tab, [(tab) => this.node.toString(tab), () => '', (tab) => this.txt.toString(tab)])
32+
'PeritextApi' + printTree(tab, [(tab) => this.node.toString(tab), () => '', (tab) => this.txt.toString(tab)])
3433
);
3534
}
3635
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ export class Block<Attr = unknown> implements IBlock, Printable, Stateful {
139139

140140
// ---------------------------------------------------------------- Printable
141141

142+
protected toStringName(): string {
143+
return 'Block';
144+
}
142145
protected toStringHeader(): string {
143146
const hash = `#${this.hash.toString(36).slice(-4)}`;
144147
const tag = `<${this.path.join('.')}>`;
145-
const header = `${this.constructor.name} ${hash} ${tag}`;
148+
const header = `${this.toStringName()} ${hash} ${tag}`;
146149
return header;
147150
}
148151

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Blocks implements Printable, Stateful {
1818
// ---------------------------------------------------------------- Printable
1919

2020
public toString(tab: string = ''): string {
21-
return this.constructor.name + printTree(tab, [(tab) => this.root.toString(tab)]);
21+
return 'Blocks' + printTree(tab, [(tab) => this.root.toString(tab)]);
2222
}
2323

2424
// ----------------------------------------------------------------- Stateful

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,18 @@ export class Inline extends Range implements Printable {
149149

150150
// ---------------------------------------------------------------- Printable
151151

152+
public toStringName(): string {
153+
return 'Inline';
154+
}
155+
152156
public toString(tab: string = ''): string {
153157
const str = this.text();
154158
const truncate = str.length > 32;
155159
const text = JSON.stringify(truncate ? str.slice(0, 32) : str) + (truncate ? ' …' : '');
156160
const startFormatted = this.start.toString(tab, true);
157161
const range =
158162
this.start.cmp(this.end) === 0 ? startFormatted : `${startFormatted}${this.end.toString(tab, true)}`;
159-
const header = `${this.constructor.name} ${range} ${text}`;
163+
const header = `Inline ${range} ${text}`;
160164
const marks = this.attr();
161165
const markKeys = Object.keys(marks);
162166
return (

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export interface IBlock<Attr = unknown> {
1010

1111
export class LeafBlock<Attr = unknown> extends Block<Attr> {
1212
// ---------------------------------------------------------------- Printable
13+
protected toStringName(): string {
14+
return 'LeafBlock';
15+
}
1316

1417
protected toStringHeader(): string {
1518
const str = this.text();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ export class Cursor<T = string> extends PersistedSlice<T> {
100100
// ---------------------------------------------------------------- Printable
101101

102102
public toStringName(): string {
103+
return 'Cursor';
104+
}
105+
106+
public toStringHeaderName(): string {
103107
const focusIcon = this.anchorSide === CursorAnchor.Start ? '.→|' : '|←.';
104-
return `${super.toStringName()}, ${focusIcon}`;
108+
return `${super.toStringHeaderName()}, ${focusIcon}`;
105109
}
106110
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ export class MarkerOverlayPoint<T = string> extends OverlayPoint<T> implements H
3232

3333
// ---------------------------------------------------------------- Printable
3434

35-
public toStringName(tab: string, lite?: boolean): string {
35+
public toStringName(): string {
36+
return 'OverlayPoint';
37+
}
38+
39+
public toStringHeader(tab: string, lite?: boolean): string {
3640
const hash = lite ? '' : `#${this.textHash.toString(36).slice(-4)}`;
3741
const tag = lite ? '' : `, type = ${JSON.stringify(this.type() as any)}`;
38-
return `${super.toStringName(tab, lite)}${lite ? '' : ' '}${hash}${tag}`;
42+
return `${super.toStringHeader(tab, lite)}${lite ? '' : ' '}${hash}${tag}`;
3943
}
4044

4145
public toString(tab: string = '', lite?: boolean): string {
4246
return (
43-
this.toStringName(tab, lite) +
47+
this.toStringHeader(tab, lite) +
4448
(lite
4549
? ''
4650
: printTree(tab, [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ export class Overlay<T = string> implements Printable, Stateful {
530530
);
531531
};
532532
return (
533-
`${this.constructor.name} #${this.hash.toString(36)}` +
533+
`Overlay #${this.hash.toString(36)}` +
534534
printTree(tab, [
535535
!this.root ? null : (tab) => printPoint(tab, this.root!),
536536
!this.root2 ? null : (tab) => printMarkerPoint(tab, this.root2!),

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,17 @@ export class OverlayPoint<T = string> extends Point<T> implements Printable, Hea
205205

206206
// ---------------------------------------------------------------- Printable
207207

208-
public toStringName(tab: string, lite?: boolean): string {
208+
public toStringName(): string {
209+
return 'OverlayPoint';
210+
}
211+
212+
public toStringHeader(tab: string = '', lite?: boolean): string {
209213
return super.toString(tab, lite);
210214
}
211215

212216
public toString(tab: string = '', lite?: boolean): string {
213217
const refs = lite ? '' : `, refs = ${this.refs.length}`;
214-
const header = this.toStringName(tab, lite) + refs;
218+
const header = this.toStringHeader(tab, lite) + refs;
215219
if (lite) return header;
216220
const children: PrintChild[] = [];
217221
const layers = this.layers;

src/json-crdt-extensions/peritext/rga/Point.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,12 @@ export class Point<T = string> implements Pick<Stateful, 'refresh'>, Printable {
449449

450450
// ---------------------------------------------------------------- Printable
451451

452+
public toStringName(): string {
453+
return 'Point';
454+
}
455+
452456
public toString(tab: string = '', lite?: boolean): string {
453-
const name = lite ? '' : this.constructor.name + ' ';
457+
const name = lite ? '' : this.toStringName() + ' ';
454458
const pos = this.pos();
455459
const id = printTs(this.id);
456460
const anchor = this.anchor === Anchor.Before ? '.▢' : '▢.';

src/json-crdt-extensions/peritext/rga/Range.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@ export class Range<T = string> implements Pick<Stateful, 'refresh'>, Printable {
231231

232232
// ---------------------------------------------------------------- Printable
233233

234+
public toStringName(): string {
235+
return 'Range';
236+
}
237+
234238
public toString(tab: string = '', lite: boolean = true): string {
235-
const name = lite ? '' : `${this.constructor.name} `;
239+
const name = lite ? '' : this.toStringName();
236240
const start = this.start.toString(tab, lite);
237241
const end = this.end.toString(tab, lite);
238242
let text = this.text();
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import {Slices} from './Slices';
22

3-
export class ExtraSlices<T = string> extends Slices<T> {}
3+
export class ExtraSlices<T = string> extends Slices<T> {
4+
public toStringName(): string {
5+
return 'ExtraSlices';
6+
}
7+
}

src/json-crdt-extensions/peritext/slice/LocalSlices.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export class LocalSlices<T = string> extends Slices<T> {
66
super.del(id);
77
if (Math.random() < 0.1) this.set.removeTombstones();
88
}
9+
10+
public toStringName(): string {
11+
return 'LocalSlices';
12+
}
913
}

src/json-crdt-extensions/peritext/slice/PersistedSlice.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,26 @@ export class PersistedSlice<T = string> extends Range<T> implements MutableSlice
164164

165165
// ---------------------------------------------------------------- Printable
166166

167-
protected toStringName(): string {
167+
public toStringName(): string {
168+
return 'Range';
169+
}
170+
171+
protected toStringHeaderName(): string {
168172
const data = this.data();
169173
const dataFormatted = data ? prettyOneLine(data) : '∅';
170174
const dataLengthBreakpoint = 32;
171-
const header = `${this.constructor.name} ${super.toString('', true)}, ${
175+
const header = `${this.toStringName()} ${super.toString('', true)}, ${
172176
SliceBehaviorName[this.behavior]
173177
}, ${JSON.stringify(this.type)}${dataFormatted.length < dataLengthBreakpoint ? `, ${dataFormatted}` : ''}`;
174178
return header;
175179
}
176180

177-
public toString(tab: string = ''): string {
181+
public toStringHeader(tab: string = ''): string {
178182
const data = this.data();
179183
const dataFormatted = data ? prettyOneLine(data) : '';
180184
const dataLengthBreakpoint = 32;
181185
return (
182-
this.toStringName() +
186+
this.toStringHeaderName() +
183187
printTree(tab, [dataFormatted.length < dataLengthBreakpoint ? null : (tab) => dataFormatted])
184188
);
185189
}

src/json-crdt-extensions/peritext/slice/Slices.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@ export class Slices<T = string> implements Stateful, Printable {
201201

202202
// ---------------------------------------------------------------- Printable
203203

204+
public toStringName(): string {
205+
return 'Slices';
206+
}
207+
204208
public toString(tab: string = ''): string {
205209
return (
206-
this.constructor.name +
210+
this.toString() +
207211
printTree(
208212
tab,
209213
[...this.list.entries()].map(

src/json-crdt-extensions/peritext/util/ChunkSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ChunkSlice<T = string> implements IChunkSlice<T>, Stateful, Printab
5656
// ---------------------------------------------------------------- Printable
5757

5858
public toString(tab: string = ''): string {
59-
const name = this.constructor.name;
59+
const name = 'ChunkSlice';
6060
const off = this.off;
6161
const len = this.len;
6262
const str = this.view() + '';

src/json-crdt-patch/Batch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Batch {
3030

3131
public toString(tab: string = ''): string {
3232
const id = this.getId();
33-
let out = `${this.constructor.name} ${id ? printTs(id) : '(nil)'}\n`;
33+
let out = `Batch ${id ? printTs(id) : '(nil)'}\n`;
3434
for (let i = 0; i < this.patches.length; i++) {
3535
const patch = this.patches[i];
3636
const isLast = i === this.patches.length - 1;

src/json-crdt-patch/Patch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class Patch implements Printable {
214214
*/
215215
public toString(tab: string = ''): string {
216216
const id = this.getId();
217-
const header = `${this.constructor.name} ${id ? printTs(id) : '(nil)'}!${this.span()}`;
217+
const header = `Patch ${id ? printTs(id) : '(nil)'}!${this.span()}`;
218218
return (
219219
header +
220220
printTree(

src/json-crdt/model/api/nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class NodeApi<N extends JsonNode = JsonNode> implements Printable {
180180
}
181181

182182
public toString(tab: string = ''): string {
183-
return this.constructor.name + printTree(tab, [(tab) => this.node.toString(tab)]);
183+
return 'api' + printTree(tab, [(tab) => this.node.toString(tab)]);
184184
}
185185
}
186186

src/json-crdt/nodes/rga/AbstractRga.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ export abstract class AbstractRga<T> {
879879
// ---------------------------------------------------------------- Printable
880880

881881
protected toStringName(): string {
882-
return this.constructor.name;
882+
return 'AbstractRga';
883883
}
884884

885885
public toString(tab: string = ''): string {
@@ -904,7 +904,7 @@ export abstract class AbstractRga<T> {
904904

905905
protected formatChunk(chunk: Chunk<T>): string {
906906
const id = printTs(chunk.id);
907-
let str = `${chunk.constructor.name} ${id}!${chunk.span} len:${chunk.len}`;
907+
let str = `chunk ${id}!${chunk.span} len:${chunk.len}`;
908908
if (chunk.del) str += ` [${chunk.span}]`;
909909
else {
910910
if (isUint8Array(chunk.data)) str += ` { ${printOctets(chunk.data) || '∅'} }`;

src/json-crdt/nodes/str/__tests__/StrNode.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,21 @@ describe('binary tree', () => {
154154
const tree = createTree();
155155
expect(tree.toString()).toMatchInlineSnapshot(`
156156
"str .0 { "a1a2a3a4a5a6a7a8a9a10a11a12a13a1" … }
157-
└─ StrChunk .8!2 len:36 { "a8" }
158-
StrChunk .4!2 len:14 { "a4" }
159-
StrChunk .2!2 len:6 { "a2" }
160-
StrChunk .1!2 len:2 { "a1" }
161-
StrChunk .3!2 len:2 { "a3" }
162-
StrChunk .6!2 len:6 { "a6" }
163-
StrChunk .5!2 len:2 { "a5" }
164-
StrChunk .7!2 len:2 { "a7" }
165-
StrChunk .12!3 len:20 { "a12" }
166-
StrChunk .10!3 len:8 { "a10" }
167-
StrChunk .9!2 len:2 { "a9" }
168-
StrChunk .11!3 len:3 { "a11" }
169-
StrChunk .14!3 len:9 { "a14" }
170-
StrChunk .13!3 len:3 { "a13" }
171-
StrChunk .15!3 len:3 { "a15" }"
157+
└─ chunk .8!2 len:36 { "a8" }
158+
chunk .4!2 len:14 { "a4" }
159+
chunk .2!2 len:6 { "a2" }
160+
chunk .1!2 len:2 { "a1" }
161+
chunk .3!2 len:2 { "a3" }
162+
chunk .6!2 len:6 { "a6" }
163+
chunk .5!2 len:2 { "a5" }
164+
chunk .7!2 len:2 { "a7" }
165+
chunk .12!3 len:20 { "a12" }
166+
chunk .10!3 len:8 { "a10" }
167+
chunk .9!2 len:2 { "a9" }
168+
chunk .11!3 len:3 { "a11" }
169+
chunk .14!3 len:9 { "a14" }
170+
chunk .13!3 len:3 { "a13" }
171+
chunk .15!3 len:3 { "a15" }"
172172
`);
173173
});
174174

src/json-crdt/nodes/str/__tests__/StrNodeFuzzer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class StrNodeSite implements Printable {
8787

8888
public toString(tab?: string): string {
8989
return (
90-
this.constructor.name +
90+
'StrNodeSite' +
9191
printTree(tab, [
9292
(tab) => 'clock ' + this.clock.toString(tab),
9393
(tab) =>
@@ -244,7 +244,7 @@ export class StrNodeFuzzer extends Fuzzer implements Printable {
244244

245245
public toString(tab?: string): string {
246246
return (
247-
this.constructor.name +
247+
'StrNodeFuzzer' +
248248
printTree(tab, [
249249
(tab) => this.sites[0].rga.toString(tab),
250250
(tab) => 'prelude ' + printPatch(tab, this.prelude),

src/json-ot/types/ot-json/tree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class Register {
112112
? '/' + this.pick.path.slice(0, this.pick.pathLength).join('/')
113113
: `{ ${JSON.stringify(this.data)} }`;
114114
const dst = drops ? `{ ${drops} }` : '∅';
115-
return `${this.id}: ${this.constructor.name} ${src} ┈┈┈→ ${dst}`;
115+
return `${this.id}: Register ${src} ┈┈┈→ ${dst}`;
116116
}
117117
}
118118

@@ -408,6 +408,6 @@ export class OpTree {
408408
i++;
409409
}
410410
const drops = this.drop ? this.drop.toString(tab + ' ') : ' ∅';
411-
return `${this.constructor.name}\n${tab}├─ ${picks}\n${tab}│\n${tab}├─ ${registers}\n${tab}│\n${tab}└─ ${drops}`;
411+
return `OpTree\n${tab}├─ ${picks}\n${tab}│\n${tab}├─ ${registers}\n${tab}│\n${tab}└─ ${drops}`;
412412
}
413413
}

src/json-type-value/ObjectValue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ export class ObjectValue<T extends classes.ObjectType<any>> extends Value<T> imp
159159
}
160160

161161
public toString(tab: string = ''): string {
162-
return this.constructor.name + printTree(tab, [(tab) => this.type.toString(tab)]);
162+
return 'ObjectValue' + printTree(tab, [(tab) => this.type.toString(tab)]);
163163
}
164164
}

src/json-type/system/TypeSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class TypeSystem implements Printable {
7474
public toString(tab: string = '') {
7575
const nl = () => '';
7676
return (
77-
this.constructor.name +
77+
'TypeSystem' +
7878
printTree(tab, [
7979
(tab) =>
8080
'aliases' +

0 commit comments

Comments
 (0)