add clear to YMap to remove all elements

This commit is contained in:
Will Hawker
2021-06-08 21:09:44 +01:00
parent 097b9e8208
commit 4b35de5ad5
3 changed files with 85 additions and 0 deletions

View File

@@ -237,6 +237,22 @@ export class YMap extends AbstractType {
return typeMapHas(this, key)
}
/**
* Removes all elements from this YMap.
*/
clear () {
if (this.doc !== null) {
transact(this.doc, transaction => {
this.forEach(function (value, key, map) {
console.log('deleting', key)
typeMapDelete(transaction, map, key)
})
})
} else {
/** @type {Map<string, any>} */ (this._prelimContent).clear()
}
}
/**
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
*/