mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-05 12:14:43 +00:00
docs: refine map.set docs
This commit is contained in:
parent
8eccf586bf
commit
83023b73bd
2 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue