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

Performs the conversion.

Performs the conversion.

The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more

Recover a Self from Self::Abi. Read more

The wasm ABI type that this converts into when crossing the ABI boundary. Read more

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary. Read more

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi. Read more

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more

The wasm ABI type references to Self are recovered from.

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

Same as RefFromWasmAbi::Abi

Same as RefFromWasmAbi::Anchor

Same as RefFromWasmAbi::ref_from_abi

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Same as IntoWasmAbi::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.