Discussions related to Shared Editing, Distributed Apps, and Yjs. Questions about Yjs should go to discuss.yjs.dev. Bug reports to the issue tracker.
Hey. I have a nested Y.Map structure like that:
parentMap<Y.Map> = {
childId1: <Y.Map> { ...childProperties },
childId2: <Y.Map> { ...childProperties }
}
and want to use the Y.UndoManager like that:
const newUndoManager = new Y.UndoManager(parentMap);
Now. I can undo and redo events on the parentMap (e.g., add child, or remove child) but not events on the childs (i.e., property changes). As I understand the docs, this should be possible. Is there somewhere an example on how to do it?
@dmonad Thanks for your responses, I have been trying to figure it out but I'm still stuck. This is an example adapting from y-websocket
- I'm basically trying to only return a subset of the result when it goes to getYDoc
Y.RelativePosition
thing: https://docs.yjs.dev/api/relative-positionsY.Doc()
. Maybe I'm seriously misunderstanding something, though.
Hi @anne_biene_twitter,
They can be used with anything that looks like an Array (Y.Text, Y.Array, Y.XmlElement, Y.XmlFragment) ;)
@MaxNoetzold, the docs that you linked explain how you can add support to your existing provider (it's only a few lines of code).
@jclem
The subdocs documentation seems to imply that creating subdocs does not merge—is this correct? What happens if client A and client B concurrently try and create a subdoc with the same key? This generally seems like it's an issue with maps since their values are last-write-wins. How could one implement something where two users may concurrently create the same text document at the same time, and you want their edits to converge?
I'm not sure how this can happen. I expect that content is usually only created by a single user. I suspect that you are implementing a problematic pattern. In order to have two users create the same(?) content at the same time, you need coordination between these users. Yjs is coordination-free, so you'd need to implement this yourself (it would be better to avoid this problematic pattern).
I think the other questions have been posted on the discussion forum as well (if they haven't they should be). I feel the chat is not a good place to ask complicated questions. It's hard to keep track. It would be better to post to discuss.yjs.dev instead.
Hi everyone,
I am currently trying to setup my own yjs backend. This backend should fulfil the following three requirements:
Is such a thing or a similar one already implemented? If so, could you provide me with such or a nice documentation? 😀
Hi everyone new to working with YJs, trying to implement yjs with code mirror on a nextjs app. I'm following this https://github.com/yjs/y-codemirror but I get an error each time saying "A Yjs doc connected to room {room name} already exists" .
Which is quite confusing because surely the room has to exist for more than 1 client to connect? Any advice on how to solve this simple bug?
I build a yjs.js file , but it can't work.
{
input: './src/index.js',
output: {
name: 'Y',
file: 'dist/yjs.js',
format: 'iife'
},
external: id => /^lib0\//.test(id)
}
then, i used <script> in html
<script src="js/yjs.js"></script>
there is an error: Uncaught ReferenceError: observable is not defined
so Yjs must depend on Nodejs?
Hi, I'm trying to use the demo server in my own Node project, but I'm getting the following error:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './bin/utils.js' is not defined by "exports" in [...]node_modules/y-websocket/package.json
This happens when trying to require
the setupWSConnections
method from y-websocket/bin/utils.js
in this line:
const setupWSConnection = require('y-websocket/bin/utils.js').setupWSConnection
My hunch is that this is may have worked with previous Node version, but perhaps broke at some point with more recent ones. Any thoughts on this? Is there an alternative way to require
the setupWSConnection
method directly from the y-websocket
package?
import * as React from 'react'
import Editor from '@monaco-editor/react'
import * as monaco from 'monaco-editor'
import * as Y from 'yjs'
import { WebrtcProvider } from 'y-webrtc'
import { MonacoBinding } from 'y-monaco'
const MonacoEditor = () => {
const ydoc = new Y.Doc()
const provider = new WebrtcProvider('room-name', ydoc)
const ytext = ydoc.getText()
const handleEditorDidMount = (editor: monaco.editor.IStandaloneCodeEditor) => {
new MonacoBinding(
ytext,
editor.getModel() as monaco.editor.ITextModel,
new Set([editor]),
provider.awareness
)
}
return (
<Editor
onMount={handleEditorDidMount}
theme="vs-dark"
height="98vh"
defaultLanguage="javascript"
/>
)
}
export default MonacoEditor
Hi, quick questions ... I thought that nested maps will also be merged, but in my case this does not seem to work. Here is an example:
doc1 = new Y.Doc()
doc2 = new Y.Doc()
db1 = doc1.getMap("db")
db2 = doc2.getMap("db")
nestedMap1 = new Y.Map()
nestedMap2 = new Y.Map()
db1.set("a", nestedMap1)
db2.set("a", nestedMap2)
nestedMap1.set("x", 111)
nestedMap2.set("y", 222)
state1 = Y.encodeStateAsUpdate(doc1)
state2 = Y.encodeStateAsUpdate(doc2)
Y.applyUpdate(doc2, state1)
Y.applyUpdate(doc1, state2)
doc1.toJSON()
// { db: { a: { y: 222 }}}
doc2.toJSON()
// { db: { a: { y: 222 }}}
What I actually require is the result { db: { a: { x: 111, y: 222 }}
. Is there a way to achieve this, or should I change my data structures?
Hi, I'm looking for a solution to use Y.js as the CRDT library with Apollo GraphQL as the network layer and MongoDB. I couldn't find any example or anything to integrate them. However since Y.js is network agnostic so I don't think there will be much challenging.
Would the architecture be something like this from top to bottom?
1) MonogoDB
2) MergeConflictResolver (Y.js):
a) Converts retrieved JSON data from DB to Y.doc
b) Converts received JSON data from GraphQL to y.doc
c) Resolves conflicts
d) Converts Y.doc to JSON
e) Stores JSON to MongoDB
3) Network Layer (Apollo GraphQL with Subscriptions and Mutations)
4) Client Browser
5) Apollo-cache as client store (JSON)
6) MergeConflictResolver (Y.js):
a) Converts retrieved JSON data from Apollo cache to Y.doc
b) Converts received JSON data from user changes to Y.doc
c) Resolves conflicts
d) Converts Y.doc to JSON
e) Sends JSON to server using Apollo GraphQL
7) Frontend components (Form/inputs...)
Please let me know if there is a redundant layer or something is missed.