How to equality check b/w two Yjs docs

Hi All,

I’m new to Yjs, and trying to figure out What’s the best way to perform equality checks b/w two Y.Doc()? I want to compare Yjs doc in the user request with the saved one in the database and save the new one only if there’s a change.

Should I convert both to

  • toJSON and compare?
  • encodeStateVector and compare?
  • create snapshots and compare using Y.equalSnapshots?

and if ther’s change then

Y.applyUpdate(savedDoc, Y.encodeStateAsUpdate(req.document))

Hi @santhosh-ps,

Y.equalSnapshots is currently the best approach :+1:

1 Like