Skip to content

Commit d3ea386

Browse files
committed
feat(json-crdt): 🎸 use .map field in obj and vec
1 parent 677e456 commit d3ea386

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/json-crdt/codec/structural/verbose/Decoder.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ export class Decoder {
5959
protected cObj(doc: Model, node: types.ObjectJsonCrdtNode): nodes.ObjNode {
6060
const id = this.cTs(node.id);
6161
const obj = new nodes.ObjNode(doc, id);
62-
const keys = Object.keys(node.keys);
62+
const map = node.map;
63+
const keys = Object.keys(map);
6364
for (const key of keys) {
64-
const keyNode = node.keys[key];
65+
const keyNode = map[key];
6566
obj.put(key, this.cNode(doc, keyNode).id);
6667
}
6768
doc.index.set(id, obj);
@@ -72,10 +73,10 @@ export class Decoder {
7273
const id = this.cTs(node.id);
7374
const obj = new nodes.VecNode(doc, id);
7475
const elements = obj.elements;
75-
const components = node.components;
76-
const length = components.length;
76+
const map = node.map;
77+
const length = map.length;
7778
for (let i = 0; i < length; i++) {
78-
const component = components[i];
79+
const component = map[i];
7980
if (!component) elements.push(undefined);
8081
else elements.push(this.cNode(doc, component).id);
8182
}

src/json-crdt/codec/structural/verbose/Encoder.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,31 @@ export class Encoder {
4343
}
4444

4545
public cObj(obj: nodes.ObjNode): types.ObjectJsonCrdtNode {
46-
const keys: Record<string, types.JsonCrdtNode> = {};
46+
const map: Record<string, types.JsonCrdtNode> = {};
4747
obj.nodes((node, key) => {
48-
keys[key] = this.cNode(node);
48+
map[key] = this.cNode(node);
4949
});
5050
return {
5151
type: 'obj',
5252
id: this.cTs(obj.id),
53-
keys,
53+
map,
5454
};
5555
}
5656

5757
public cVec(obj: nodes.VecNode): types.TupleJsonCrdtNode {
58-
const components: types.TupleJsonCrdtNode['components'] = [];
58+
const map: types.TupleJsonCrdtNode['map'] = [];
5959
const elements = obj.elements;
6060
const length = elements.length;
6161
const index = this.model.index;
6262
for (let i = 0; i < length; i++) {
6363
const element = elements[i];
64-
if (element === undefined) components.push(null);
65-
else components.push(this.cNode(index.get(element)!));
64+
if (element === undefined) map.push(null);
65+
else map.push(this.cNode(index.get(element)!));
6666
}
6767
return {
6868
type: 'tup',
6969
id: this.cTs(obj.id),
70-
components,
70+
map,
7171
};
7272
}
7373

src/json-crdt/codec/structural/verbose/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface ValueJsonCrdtNode {
5151
export interface ObjectJsonCrdtNode {
5252
type: 'obj';
5353
id: JsonCrdtTimestamp;
54-
keys: Record<string, JsonCrdtNode>;
54+
map: Record<string, JsonCrdtNode>;
5555
}
5656

5757
/**
@@ -60,7 +60,7 @@ export interface ObjectJsonCrdtNode {
6060
export interface TupleJsonCrdtNode {
6161
type: 'tup';
6262
id: JsonCrdtTimestamp;
63-
components: (null | JsonCrdtNode)[];
63+
map: (null | JsonCrdtNode)[];
6464
}
6565

6666
/**

0 commit comments

Comments
 (0)