* Removes an index from this collection. * Returns true when an index existed and was removed, false otherwise.
(indexOrId: BaseIndex<TKey> | number)
| 302 | * Returns true when an index existed and was removed, false otherwise. |
| 303 | */ |
| 304 | public removeIndex(indexOrId: BaseIndex<TKey> | number): boolean { |
| 305 | this.lifecycle.validateCollectionUsable(`removeIndex`) |
| 306 | |
| 307 | const indexId = typeof indexOrId === `number` ? indexOrId : indexOrId.id |
| 308 | const index = this.indexes.get(indexId) |
| 309 | if (!index) { |
| 310 | return false |
| 311 | } |
| 312 | |
| 313 | if (typeof indexOrId !== `number` && index !== indexOrId) { |
| 314 | // Passed a different index instance with the same id — do not remove. |
| 315 | return false |
| 316 | } |
| 317 | |
| 318 | this.indexes.delete(indexId) |
| 319 | |
| 320 | const metadata = this.indexMetadata.get(indexId) |
| 321 | this.indexMetadata.delete(indexId) |
| 322 | if (metadata) { |
| 323 | this.events.emitIndexRemoved(metadata) |
| 324 | } |
| 325 | |
| 326 | return true |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Returns a sorted snapshot of index metadata. |
nothing calls this directly
no test coverage detected