Skip to content

Commit 7525885

Browse files
committed
feat(json-crdt): 🎸 improve how model view is printed in .toString()
1 parent a6e83c8 commit 7525885

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/json-crdt/__demos__/type-safety.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import {Model, n} from '..';
1010

11+
console.clear();
12+
1113
const model = Model.withLogicalClock(1234) as Model<
1214
n.obj<{
1315
num: n.con<number>;

src/json-crdt/model/Model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,15 @@ export class Model<RootJsonNode extends JsonNode = JsonNode> implements Printabl
347347
this.index.forEach((item) => nodes.push(item.v));
348348
return (
349349
`Index (${nodes.length} nodes)` +
350-
printTree(
350+
(nodes.length ? printTree(
351351
tab,
352352
nodes.map((node) => (tab) => `${node.constructor.name} ${toDisplayString(node.id)}`),
353-
)
353+
) : '')
354354
);
355355
},
356356
nl,
357357
// (tab) => `View ${toTree(this.view(), tab)}`,
358-
(tab) => `View${printTree(tab, [(tab) => JSON.stringify(this.view(), null, 2).replace(/\n/g, '\n' + tab)])}`,
358+
(tab) => `View${printTree(tab, [(tab) => String(JSON.stringify(this.view(), null, 2)).replace(/\n/g, '\n' + tab)])}`,
359359
nl,
360360
(tab) => this.clock.toString(tab),
361361
hasExtensions ? nl : null,

0 commit comments

Comments
 (0)