YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.

Home Page:https://syncedstore.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sorting an array in Synced Store

websiddu opened this issue · comments

I have an array in synced store and I wanted to sort

I'm using

const [removed] = store.nodes.splice(srcIndex, 1);
store.nodes.splice(destIndex, 0, removed)

I keep getting an error Not supported: reassigning object that already occurs in the tree.

Never mind, i was trying to add a proxy object directly, and when I convert the proxy to JS it worked fine.

Alright! Best to do sorting on a non-synced copy of the array indeed

And what's the recommended way to convert the proxied array to JS? array.slice(0)?

you use lodash's copy function or just do JSON.parse(JSON.stringify(proxyObject))

@websiddu That seems pretty inefficient. Wouldn''t it make sense to add a method to the proxy which allows direct access to the underlying array (or similar)?

Also, maybe I am missing something, but as it is not possible to replace the array in the store, how can I change the sort order in the stored array permanently? Or is this not supported and I should rather add a position property to each item instead?