Skip to content

Commit 66da4b9

Browse files
committed
fix(json-crdt): 🐛 correctly iterate through object
1 parent eccb1a3 commit 66da4b9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/json-crdt/__tests__/fuzzer/Picker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Picker {
4848
if (Math.random() > 0.45) return [this.generateObjectKey(), InsObjOp];
4949
const keys = [...node.keys.keys()];
5050
if (!keys.length) return [this.generateObjectKey(), InsObjOp];
51-
const key = keys[Math.floor(Math.random() * keys.length)];
51+
const key = Fuzzer.pick(keys);
5252
return [key, DelOp];
5353
}
5454

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as nodes from '../../../nodes';
22
import {ClockDecoder} from '../../../../json-crdt-patch/codec/clock/ClockDecoder';
33
import {ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock';
44
import {Model, UNDEFINED} from '../../../model/Model';
5-
import {JsonCrdtDataType, ORIGIN, SESSION} from '../../../../json-crdt-patch/constants';
5+
import {JsonCrdtDataType, SESSION} from '../../../../json-crdt-patch/constants';
66
import type * as t from './types';
77

88
export class Decoder {
@@ -83,7 +83,10 @@ export class Decoder {
8383
const id = this.ts(node[1]);
8484
const obj = new nodes.ObjNode(model, id);
8585
const map = node[2] as t.JsonCrdtCompactObj[2];
86-
for (const key in map) {
86+
const keys = Object.keys(map);
87+
const length = keys.length;
88+
for (let i = 0; i < length; i++) {
89+
const key = keys[i];
8790
const val = this.decNode(model, map[key]);
8891
obj.put(key, val.id);
8992
}

0 commit comments

Comments
 (0)