0.7.2 • Published 9 days ago
@dgmjs/dgmjs-plugin-yjs v0.7.2
yjs sync plugin
user1 user2
+---------------------+ +---------------------+
+-------+ +------+ +------+ +-------+
| Store | ---> | yDoc | <--(sync)--> | yDoc | ---> | Store |
+-------+ +------+ +------+ +-------+
plugin setup
function App() {
return (<DGMEditor plugins=[new YjsDocSyncPlugin()]>)
}
class YjsDocSyncPlugin {
constructor () {
super('@dgmjs/yjs-doc-sync')
}
/** start live syn */
start(yDoc, yProvider) {}
/** stop live sync */
stop() {}
/* flush objs to yDoc */
flush() {}
}
sync
- sync to ydoc
- sync to store
Sync to yDoc
Apply Transaction
to Y.Map
create
mutation- convert
obj
toyObj
- set
obj.id
,yObj
inyObjMap
- convert
delete
mutation- delete
obj.id
fromyObjMap
- delete
assign
mutation- get
yObj
byobj.id
fromyObjMap
- set
field
,value
inyObj
- get
assign-ref
mutation- get
yObj
byobj.id
fromyObjMap
- set
field
,value.id
inyObj
- get
insert-child
mutation- get
yObj
byparent.id
fromyObjMap
- let po = compute
parent:order
ofyObj
based onposition
- set
parent
,parent.id
inyObj
- set
parent:order
, po inyObj
- get
remove-child
mutation- get
yObj
byparent.id
fromyObjMap
- delete
parent
fromyObj
- delete
parent:order
fromyObj
- get
reorder-child
mutation- get
yObj
byparent.id
fromyObjMap
- let po = compute
parent:order
ofyObj
based onposition
- set
parent:order
, po inyObj
- get
Convert obj
to yObj
Sync to Store
- yObjMap
add
change - yObjMap
delete
change - yObj
add
change - yObj
delete
change - yObj
update
change
parent:order
Setting
parent:order
- in
flush()
- applying/unapplying
InsertChild
mutation - applying/unapplying
RemoveChild
mutation - applying/unapplying
ReorderChild
mutation
- in
Reading
parent:order
YObj
createdparent
changed
get parent order
orders = [0, 1, 2, 3, 4, 5]
:get order of oldPositon = null, newPosition = 1;
- between(0, 1): [0, (0.5), 1, 2, 3, 4, 5]
:get order of oldPositon = null, newPosition = 0;
- before(0): [(-1), 0, 1, 2, 3, 4, 5]
:get order of oldPositon = null, newPosition = 6;
- after(5): [0, 1, 2, 3, 4, 5, (6)]
:get order of oldPositon = 0, newPosition = 1;
- remove: [1, 2, 3, 4, 5]
- between(0, 1): [1, (1.5), 2, 3, 4, 5]
:get order of oldPositon = 0, newPosition = 5;
- remove: [1, 2, 3, 4, 5]
- after(4): [1, 2, 3, 4, 5, (6)]