Giter Club home page Giter Club logo

Comments (7)

dmonad avatar dmonad commented on July 18, 2024

Usually, remote changes are not tracked by Y.UndoManager.

But if you configured it to track remote changes:
Is this issue really specific to Y-CRDT as a remote client?

from yjs.

davidbrochart avatar davidbrochart commented on July 18, 2024

How can I configure it to track remote changes?

from yjs.

davidbrochart avatar davidbrochart commented on July 18, 2024

I saw the undo manager ignoreRemoteMapChanges: true option, but it doesn't have any effect.
Basically this is what I am trying to do:

const Y = require('yjs')

const doc0 = new Y.Doc()
const doc1 = new Y.Doc()

doc0.on('update', update => {
  Y.applyUpdate(doc1, update)
})

doc1.on('update', update => {
  Y.applyUpdate(doc0, update)
})

const map0 = doc0.getMap('map')
const map1 = doc1.getMap('map')

const undoManager = new Y.UndoManager(map1)

map0.set('key0', 'val0')
console.log(map1.toJSON())

undoManager.undo()
console.log(map1.toJSON())

Which works fine, because it prints:

{ key0: 'val0' }
{}

The undo manager did undo the remote change.
So it seems that the issue is specific to y-crdt as a remote client.

from yjs.

dmonad avatar dmonad commented on July 18, 2024

I don't think so. If you use y-websocket, you need to add the y-websocket provider instance as a tracked origin. Then it should work fine.

Yjs & Y-CRDT should always generate the same updates. Since this is a basic case, I don't expect that they generate different updates that would result in an issue.

from yjs.

davidbrochart avatar davidbrochart commented on July 18, 2024

If you use y-websocket, you need to add the y-websocket provider instance as a tracked origin.

Thanks, that worked. But is it documented somewhere?

from yjs.

dmonad avatar dmonad commented on July 18, 2024

https://docs.yjs.dev/api/undo-manager

Optionally, you may specify trackedOrigins to filter specific changes. By default, all local changes will be tracked.

I updated it to:

Optionally, you may specify trackedOrigins to track changes from different sources. By default, all local changes that don't specify an origin will be tracked.

Feel free to contribute to the docs. I think it already explains how origins can be used.

from yjs.

davidbrochart avatar davidbrochart commented on July 18, 2024

That part was fine, but I think there should be a mention that y-websocket adds the WebSocket provider as an origin to the changes (that was the information I was missing).

from yjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.