docs: refine map.set docs
Some checks failed
Release WASM / Release (push) Has been cancelled
Test All / build (push) Has been cancelled

This commit is contained in:
Zixuan Chen 2025-02-01 17:31:34 +08:00
parent 8eccf586bf
commit 83023b73bd
No known key found for this signature in database
2 changed files with 10 additions and 2 deletions

View file

@ -5945,6 +5945,7 @@ interface LoroMovableList<T = unknown> {
*/
setContainer<C extends Container>(pos: number, child: C): T extends C ? T : C;
}
interface LoroMap<T extends Record<string, unknown> = Record<string, unknown>> {
new(): LoroMap<T>;
/**
@ -5998,9 +5999,13 @@ interface LoroMap<T extends Record<string, unknown> = Record<string, unknown>> {
*/
get<Key extends keyof T>(key: Key): T[Key];
/**
* Set the key with the value.
* Set the key with the value.
*
* If the value of the key is exist, the old value will be updated.
* If the key already exists, its value will be updated. If the key doesn't exist,
* a new key-value pair will be created.
*
* > **Note**: When calling `map.set(key, value)` on a LoroMap, if `map.get(key)` already returns `value`,
* > the operation will be a no-op (no operation recorded) to avoid unnecessary updates.
*
* @example
* ```ts

View file

@ -1373,6 +1373,9 @@ impl LoroMap {
}
/// Insert a key-value pair into the map.
///
/// > **Note**: When calling `map.set(key, value)` on a LoroMap, if `map.get(key)` already returns `value`,
/// > the operation will be a no-op (no operation recorded) to avoid unnecessary updates.
pub fn insert(&self, key: &str, value: impl Into<LoroValue>) -> LoroResult<()> {
self.handler.insert(key, value)
}