Determining whether a transaction is local

Using, for example, ymap.observe:

ymap.observe(function(YMapEvent, Transaction)) Registers a change observer that will be called synchronously every time this shared type is modified

there seems to be at least three ways of finding out whether the change is local to this client:

  1. event.transaction.origin is null
  2. event.transaction.local is true
  3. save the local clientID with the value when a new value is set using ymap.set() and check this.

Which is the best? Will they all work equivalently?

I use transaction.local for this determination since its name implies its meaning. That said, I don’t know if there is a technical reason to prefer other methods.

You should prefer transaction.local to determine if a transaction was created locally. All changes from the providers are local = false.

The third method won’t work when you only delete a property (as there is no item created with an id).

If possible, you should actually use transaction.origin to determine the origin of a transaction. If the change was created by a provider (or an editor-binding) the provider-instance will be set as the origin (respectively the editor-binding instance). I want to establish a pattern that each library set the origin when they create a change. Users can create changes with just null or create their own origin.