Struct ywasm::YMap [−][src]
pub struct YMap(_);
Expand description
Collection used to store key-value entries in an unordered manner. Keys are always represented as UTF-8 strings. Values can be any value type supported by Yrs: JSON-like primitives as well as shared data types.
In terms of conflict resolution, Map uses logical last-write-wins principle, meaning the past updates are automatically overridden and discarded by newer ones, while concurrent updates made by different peers are resolved into a single value using document id seniority to establish order.
Implementations
Creates a new preliminary instance of a YMap
shared data type, with its state
initialized to provided parameter.
Preliminary instances can be nested into other shared data types such as YArray
and YMap
.
Once a preliminary instance has been inserted this way, it becomes integrated into ywasm
document store and cannot be nested again: attempt to do so will result in an exception.
Returns true if this is a preliminary instance of YMap
.
Preliminary instances can be nested into other shared data types such as YArray
and YMap
.
Once a preliminary instance has been inserted this way, it becomes integrated into ywasm
document store and cannot be nested again: attempt to do so will result in an exception.
Returns a number of entries stored within this instance of YMap
.
Converts contents of this YMap
instance into a JSON representation.
Sets a given key
-value
entry within this instance of YMap
. If another entry was
already stored under given key
, it will be overridden with new value
.
Removes an entry identified by a given key
from this instance of YMap
, if such exists.
Returns value of an entry stored under given key
within this instance of YMap
,
or undefined
if no such entry existed.
Returns an iterator that can be used to traverse over all entries stored within this
instance of YMap
. Order of entry is not specified.
Example:
import YDoc from 'ywasm'
/// document on machine A
const doc = new YDoc()
const map = doc.getMap('name')
const txn = doc.beginTransaction()
try {
map.set(txn, 'key1', 'value1')
map.set(txn, 'key2', true)
for (let [key, value] of map.entries(txn)) {
console.log(key, value)
}
} finally {
txn.free()
}
Trait Implementations
The type that holds the reference to Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous. Read more
Recover a Self::Anchor
from Self::Abi
. Read more