3 ms·
It doesn't do any diffing, but keeps track of operations underneath, and syncs those. The gist is something like this: - if you push a string "hello" to an arr
by YousefED 5y ago
It doesn't do any diffing, but keeps track of operations underneath, and syncs those. The gist is something like this:
- if you push a string "hello" to an array, it will sync an update [push "hello" to Array x] along with some metadata
- if you modify a property "prop" and set it to "value" it will sync an update [set "prop" to "value"] along with some metadata
It will not automatically diff these with the previous value (in a distributed system it's difficult to say what the "previous value" was, but it will sync only those properties that have been changed). For text heavy operations, you can use the Text structure which will sync fine-grained operations ([delete 4 characters at position 2] or [insert "world" at position 5]). This makes it suitable for collaborating on rich text documents (similar to Google Docs), see: https://syncedstore.org/docs/advanced/richtext https://syncedstore.org/docs/advanced/richtext.
This might also be an interesting resource to learn how the Yjs internals work (SyncedStore builds on top of this): https://github.com/yjs/yjs/blob/main/INTERNALS.md https://github.com/yjs/yjs/blob/main/INTERNALS.md