YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.
https://syncedstore.org
MIT License
1.71k stars 51 forks source link

SyncedText is not a valid synced object #56

Closed jonassiewertsen closed 2 years ago

jonassiewertsen commented 2 years ago

SyncedText does throw an exception as show in the example below:

I would except that SyncedText is a valid synced object.

import { SyncedText, syncedStore, observeDeep } from "@syncedstore/core";

export const store = syncedStore({ myObject: {} });
store.myObject.myText = new SyncedText("hello");

observeDeep(store.myObject.myText, () => { // Does throw an exception
  store.myObject.myText.toString();
});

store.myObject.myText.insert(0, "My name is Bob, ");

I did create a codesandbox example, so it can be reproduced easily: https://codesandbox.io/s/syncedstore-syncedtext-issue-kpomzt?file=/src/index.js:0-386

This part has been taken from the docs: https://syncedstore.org/docs/advanced/text#syncedtext-objects

jonassiewertsen commented 2 years ago

The following seems to be a solution:

store.myObject.myText.observeDeep(() => {
  // Do whatever you want.
});
YousefED commented 2 years ago

Thanks, this was a bug indeed, fixed in the latest release!