Struct ywasm::YArray [−][src]
pub struct YArray(_);
Expand description
A collection used to store data in an indexed sequence structure. This type is internally implemented as a double linked list, which may squash values inserted directly one after another into single list node upon transaction commit.
Reading a root-level type as an YArray means treating its sequence components as a list, where every countable element becomes an individual entity:
- JSON-like primitives (booleans, numbers, strings, JSON maps, arrays etc.) are counted individually.
- Text chunks inserted by Text data structure: each character becomes an element of an array.
- Embedded and binary values: they count as a single element even though they correspond of multiple bytes.
Like all Yrs shared data types, YArray is resistant to the problem of interleaving (situation when elements inserted one after another may interleave with other peers concurrent inserts after merging all updates together). In case of Yrs conflict resolution is solved by using unique document id to determine correct and consistent ordering.
Implementations
Creates a new preliminary instance of a YArray
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 YArray
.
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.
Converts an underlying contents of this YArray
instance into their JSON representation.
Inserts a given range of items
into this YArray
instance, starting at given index
.
Appends a range of items
at the end of this YArray
instance.
Deletes a range of items of given length
from current YArray
instance,
starting from given index
.
Returns an element stored under given index
.
Returns an iterator that can be used to traverse over the values stored withing this
instance of YArray
.
Example:
import YDoc from 'ywasm'
/// document on machine A
const doc = new YDoc()
const array = doc.getArray('name')
const txn = doc.beginTransaction()
try {
array.push(txn, ['hello', 'world'])
for (let item of array.values(txn)) {
console.log(item)
}
} 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