Y.Array vs Y.Map for syncing list data that changes

Yjs is working sooo well for syncing 9+ sessions of code within a single YDoc = this is amazing!
Now I’m trying to store and display that list of 9+ sessions as a Y.Array for keeping track of its ID and NAME. I have more experience with array’s, so I figured that I would just store an array of objects, ie: {id:1, name:'Session 1'}. This worked fine, until trying to allow users to rename their session and was surprised that Y.Array had no set() function to overwrite data? So instead I’ve tried deleting that index and replacing it – then having all clients refresh the list of available sessions (pulldown select). Just noticed that it wasn’t always deleting itself from the array causing an issue (surely my own codes bug). (edit, just found my BUG! aargh… this technique is now working… though question still remains)

Just wanted to ask if there’s a reason that Y.Array data doesn’t have a function to change the value of an index (or it does and I didn’t see it)? I noticed that Y.Map has a get() and set() – and I can cycle through it just like an array = guess I should be using that (and read more about map’s since Yjs uses it a lot…)

TLDR; – When is it better to use Y.Array versus Y.Map, and can Y.Array also overwrite data or best to use Y.Map for that?

To “edit” plain Javascript objects in a Y.Array, I believe you’d need to delete the old object, and insert the new object in its place.

Keep in mind that you can nest shared types, for example:

Y.Array [
  Y.Map {
    id: 1,
    name: 'Session 1'
  },
  Y.Map {
      id: 2,
      name: 'Session 2'
  },
]

Grabbing a reference to the Y.Map at Array[0] and set()'ing the name to ‘New Session 1’, I think would get you the editing behavior you are looking for.

You can also use a Y.Map at the top level keyed by IDs, but in my experience that works best with 1) small collections (n < 1000), with 2) short keys. I recommend benchmarking your extreme cases if you’re worried about it.