![const doc = new LoroDoc(); doc.setPeerId(0); doc.subscribePreCommit((e) => { const changes = doc.exportJsonInIdSpan(e.changeMeta); expect(changes).toHaveLength(1); const hash = crypto.createHash("sha256"); const change = { ...changes[0], deps: changes[0].deps.map((d) => { const depChange = doc.getChangeAt(idStrToId(d)); return depChange.message; }), }; hash.update(JSON.stringify(change)); const sha256Hash = hash.digest("hex"); e.modifier.setMessage(sha256Hash); }); console.log(change); // The output is shown below doc.getList("list").insert(0, 100); doc.commit(); // Change 0 // { // id: '0@0', // timestamp: 0, // deps: [], // lamport: 0, // msg: undefined, // ops: [ // { // container: 'cid:root-list:List', // content: { type: 'insert', pos: 0, value: [100] }, // counter: 0 // } // ] // } doc.getList("list").insert(0, 200); doc.commit(); expect(doc.getChangeAt({ peer: "0", counter: 0 }).message) .toBe("2a](https://pbs.twimg.com/media/GnqW3BfagAAUQhe.jpg?name=small&format=webp)
ALT const doc = new LoroDoc(); doc.setPeerId(0); doc.subscribePreCommit((e) => { const changes = doc.exportJsonInIdSpan(e.changeMeta); expect(changes).toHaveLength(1); const hash = crypto.createHash("sha256"); const change = { ...changes[0], deps: changes[0].deps.map((d) => { const depChange = doc.getChangeAt(idStrToId(d)); return depChange.message; }), }; hash.update(JSON.stringify(change)); const sha256Hash = hash.digest("hex"); e.modifier.setMessage(sha256Hash); }); console.log(change); // The output is shown below doc.getList("list").insert(0, 100); doc.commit(); // Change 0 // { // id: '0@0', // timestamp: 0, // deps: [], // lamport: 0, // msg: undefined, // ops: [ // { // container: 'cid:root-list:List', // content: { type: 'insert', pos: 0, value: [100] }, // counter: 0 // } // ] // } doc.getList("list").insert(0, 200); doc.commit(); expect(doc.getChangeAt({ peer: "0", counter: 0 }).message) .toBe("2a










