Multiple "subdocs" events after deleting a subdoc

It may be good to know: according to my experiments, deleting subdocs will generate multiple “subdocs” events.

Just try the following code and see yourself:

  const sharedDoc = new Y.Doc()
    sharedDoc.on('subdocs', (Event) => {
      const { added, removed, loaded } = Event
      console.log('  # added',added.size, '# removed',removed.size, '# loaded',loaded.size)
      console.log('  # SubDocs:',sharedDoc.getSubdocs().size)
    })

/**** create new SubDocs (will also automatically be loaded) ****/

  const sharedMap = sharedDoc.getMap('sharedMap')
    console.log('adding subdoc to outer map')
    sharedMap.set('doc', new Y.Doc())

    console.log('adding subdoc to map in outer map')
    sharedMap.set('map', new Y.Map())
    sharedMap.get('map').set('doc', new Y.Doc())

    console.log('adding subdoc to array in outer map')
    sharedMap.set('array', new Y.Array())
    sharedMap.get('array').insert(0,[new Y.Doc()])
  const sharedArray = sharedDoc.getArray('sharedArray')
    console.log('adding subdoc to outer array')
    sharedArray.insert(0,[new Y.Doc()])

    console.log('adding subdoc to map in outer array')
    sharedArray.push([new Y.Map()])
    sharedArray.get(1).set('doc', new Y.Doc())

    console.log('adding subdoc to array in outer array')
    sharedArray.push([new Y.Array()])
    sharedArray.get(2).insert(0,[new Y.Doc()])

/**** now delete them again ****/

  console.log('removing subdoc from outer map')
  sharedMap.set('doc', null)

  console.log('removing subdoc from map in outer map')
  sharedMap.get('map').set('doc', null)

  console.log('removing subdoc from array in outer map')
  sharedMap.get('array').delete(0,1)

  console.log('removing all subdocs from outer array')
  sharedArray.delete(0,3)