import PackedBuffer from '../thunk/packed'; import { NotifyChangeType } from './common'; import { CollectionElement, Element } from './element'; import AugmentedObjectManager, { AugmentedType } from './manager'; declare class MyType implements AugmentedType { readonly name = "array"; isNativeTypeCompatible(x: unknown): x is any[]; createFromExisting(mgr: AugmentedObjectManager, ser: PackedBuffer | ArrayElement): ArrayElement; createFromNative(mgr: AugmentedObjectManager, x: any[]): ArrayElement; } declare const MY_TYPE: MyType; export default MY_TYPE; /** * A child element in an array. */ interface Node { /** * Immutable string uniquely identifying the child, or "_" for the virtual head Node. */ readonly id: string; /** * ID of the child who is its causal parent, or "" for the virtual head Node. */ causalId: string; /** * True for living nodes, false if the node has been deleted. (Read/Write, allowing for "undo"). */ alive: boolean; /** * Data payload for the element, or `UNDEFINED_SENTINAL` if this is an "undefined" slot in the JavaScript array. */ data: any; } /** * An element mimicking a JavaScript Array, with all read and write functions intact, with OR-semantics on * elements added and removed, with intent-preservation via a causal tree, with arbitrary augmented objects * for data elements which themselves will synchronize. */ export declare class ArrayElement extends CollectionElement { /** * Map of Nodes, indexed by their ID. Includes deletions. This is an Augmented Object. */ private readonly nodes; /** * The Element associated with `nodes`. */ private readonly nodesEl; /** * Array of Nodes, their current order according to this replica. Not serialized; constructed in memory. */ private readonly nodeList; /** * The JavaScript array, containing the Node's data payloads, for true-to-life simulation, and fast (native) operations most of the time. */ private readonly values; /** * The proxied version of `values`. */ private readonly proxied; constructor(mgr: AugmentedObjectManager, ser?: PackedBuffer | ArrayElement); toPackedBuffer(buf: PackedBuffer): void; private _recreateArraysFromCausalTree; /** * Keeping the `values` array object, so all associated pointers still work, reset it to zero, and fill it with * the values in the current order of `nodeList`. */ private _recreateValueListFromNodeList; /** * Returns the ID of the element at the given array index, or empty string if off the end of the list, * or "_" if it's the virtual head of the list. */ getElementId(idx: number): string; get type(): MyType; get boolean(): boolean; get number(): number; valueOf(): any; toStateString(depth?: number): string; get string(): string; get size(): number; get fullSize(): number; get children(): Iterable; /** * Sets existing element to a new Javascript value. */ setIndexedJavaScriptValue(idx: number, x: unknown, type: NotifyChangeType): void; /** * Directly set the length of the array, just as you can do with JavaScript arrays. * If expanded, the new slots are undefined. If contracted, it is essentially a deletion. */ setLength(len: number): void; set(x: unknown): boolean; /** * Same as the Array counterpart. */ splice(...args: any[]): any[]; /** * Like the JavaScript Array function, but the parameters need to be in correct range, and they're not optional. * * @param insertions can be an array of JavaScript values to insert, or a number of hole-slots to create, or the number `0` to indicate no insertions * @returns the array of deletions from the `values` array, same as `Array.splice()`. */ _splice(start: number, deleteCount: number, insertions: any[] | number, type: NotifyChangeType): any[]; /** * Creates and saves a new Node; updates `nodes` but none of our arrays. */ _createNode(causalId: string, x: unknown): Node; synchronize(src: this): void; /** * Resets all causal pointers to point to the "next" in their current order. * The result is an identical array, but with causal history reset. */ causalLinearize(): void; /** * Like the Array version, but preserves the element identities so that changes to elements remain synchronized. */ reverse(): void; /** * Like the Array version, but preserves the element identities so that changes to elements remain synchronized. */ sort(comparer: (a: any, b: any) => number): void; /** * Like the Array version, but preserves the element identities so that changes to elements remain synchronized. */ copyWithin(target: number, start: number, end?: number): void; }