Right, although it would make sense to set a denounce for extracting the values as this is potentially an expensive task to perform on every keystroke.
There is no naming convention. I actually prefer to set the provider object as the origin. You can potentially have two providers accessing the same document. In this case, you want to know if “this” provider performed the change or any other object.
For generic about whether a transaction was created remotely, you can create a remote transaction
.
// the third parameter of Y.transact marks a transaction as remote
Y.transact(ydoc, () => {
Y.applyUpdate(ydoc, update)
}, provider, true)
Then you can check whether an update was created remotely:
ydoc.on('update', (update, transaction) => {
transaction.remote // => true iff update was created remotely
})
Note that ydoc.transact
doesn’t have a third parameter.
I recommend to mark transactions as remote
when the update was created remotely. This is useful meta-information. But for filtering updates (so you don’t store the same update again when you receive an update from pouch), I recommend to set origin = pouchProvider
, and then perform an identity check on origin === this.provider
when you want to store the object.
I recommend to whitelist origins that you want to track instead of tracking everything that was not created remotely. You might be able to use the transaction.remote
flag, although I don’t recommend that.
Not that I know of. The awareness protocol as weak guarantees that the clients can elect a “primary user”. You probably want to use something like etcd for electing a primary user. If possible, you should avoid this concept.
Nice