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

"property not found on root doc then" when using promises

vincesp opened this issue · comments

Using syncedStore with a promise will yield a warning message when the promise is resolved.

Example code:

const storePromise = new Promise((resolve) => {
  ysocketio.on('document-loaded', (doc) => {
    if (doc.name === storeDef.name) {
      resolve(syncedStore(storeDef.shape, doc))
    }
  })
})

const store = await storePromise will yield the following message on the console:

property not found on root doc then

Thanks for reporting. This warning is there to warn users that are using syncedstore wrongly, by querying for non-registered properties on the root doc. In your case, the way Promises are implemented, the browser probably queries for "then".

My assumption is nothing breaks in your app, right? In that case I'll mark the issue as closed, as at this moment, I don't think (unless many people run into this) we should hardcode an exception for the warning

You are right, nothing breaks; and adding then: {} to the doc's shape suppresses the warning.

Yet, the warning is a bit confusing and only little useful. One could argue that it actually would be more useful to issue a warning if somebody ever tried to create a property then on the root doc – as that probably would cause some trouble down the line, not with syncedStore itself, but with another very common JavaScript pattern ("Thenable").