Skip to content

Type Editor


Type Editor / @type-editor/history / state/create-rope-sequence

state/create-rope-sequence

Classes

ClassDescription

Append

Internal node in the rope sequence tree structure. Combines two child rope sequences (left and right) without copying their elements.

Leaf

Leaf node in the rope sequence tree structure. Contains an array of actual elements with no child nodes.

Variables

VariableDescription

EMPTY_ROPESEQUENCE

A shared empty rope sequence instance for optimization purposes. Use this instead of creating new empty rope sequences.

Functions

FunctionDescription

createRopeSequence

Create a rope sequence from an array or return the rope if already a rope sequence.

This is a factory function that efficiently handles both array and rope sequence inputs. If the input is already a rope sequence, it returns it unchanged. If it's an array, it creates a new Leaf node, or returns an empty rope if the array is empty.

Example

typescript
const rope1 = createRopeSequence([1, 2, 3]);
const rope2 = createRopeSequence(rope1); // Returns rope1
const empty = createRopeSequence([]); // Returns Leaf.EMPTY