y-js/y-array

How to insert customized object?

Closed this issue · 1 comments

I tried to insert a Yarray with my own property.

it looks like this:

yarray.insert(yarray.length, [{arr: Y.Array, type: thisObj.state.type}])
...
...
...
elt = yarray.get(some_index).arr;

but it seems that elt is no longer a Yarray, it doesn't have the properties.

For array.insert(pos, o) the parameter o must either be a valid JSON object (it must be stringifyable), or a Yjs type (e.g. Y.Array). But you can't put a type in a JSON object.

Querying the JSON object for Yjs types is too expensive, and the problem is solved by restructuring your data. So I don't want to implement it.