valtiojs / valtio-yjs

valtio-yjs makes yjs state easy
MIT License
270 stars 15 forks source link

Simple unified api? #3

Closed dai-shi closed 2 years ago

dai-shi commented 3 years ago

Current:

import { bindProxyAndYMap, bindProxyAndYArray } from 'valtio-yjs';

bindProxyAndYMap(objProxy, ymap);
bindProxyAndYArray(arrProxy, yarray);

Proposal:

import { bind } from 'valtio-yjs';

bind(objProxy, ymap);
bind(arrProxy, yarray);
cqh963852 commented 2 years ago

While bind a proxy and yValue, If there is a difference in the data between them, how should one choose?

Such as proxy:

{
"a":"a"
}

yMap

{
"b":"b"
}

I tend the default behavior is to merge the data from both. But there keep a user-defined way.

dai-shi commented 2 years ago

I think merging {"a":"a"} and {"b":"b"} is easy. Merge from both. What would be difficult is {"a":"a"} and {"a":undefined}. I would prioritize yjs to proxy, because yjs is closer to backend. My preference is not to have an option for this, but it can't be helped with certain use cases. Do you see any use case where you need to prioritize proxy to yjs?