Skip to main content

Overview

reatomLinkedList creates an atom that manages a doubly-linked list data structure with built-in methods for efficient node creation, removal, swapping, and movement. It’s ideal for managing ordered collections where frequent reordering or insertion/deletion operations are needed.

Import

Type Signature

Symbols

LL_PREV and LL_NEXT

Each linked list instance has unique symbols for traversing nodes:

Parameters

reatomLinkedList has multiple overloads for different initialization patterns:

With Array of Initial State

Array<Node>
An array of initial node objects
string
Optional name for debugging

With Creator Function

(...params: Params) => Node
A function that creates a node from parameters

With Options Object

(...params: Params) => Node
Function to create nodes from parameters
Array<Node>
Initial nodes to populate the list
Array<Params>
Parameters to create initial nodes
Key
Key field to create a reactive map of nodes by key

Properties

array

A computed atom containing all nodes as an array. Type: Computed<Array<LLNode<Node>>>

map

When a key is specified, provides a reactive Map from key values to nodes. Type: Atom<Map<State<Node[Key]>, LLNode<Node>>>

Methods

create

Creates and appends a new node to the end of the list.
Params
Parameters passed to the creator function
Returns: LLNode<Node> - The created node

createMany

Creates and appends multiple nodes at once.
Array<Params>
Array of parameter sets for creating nodes
Returns: Array<LLNode<Node>> - The created nodes

remove

Removes a node from the list.
LLNode<Node>
The node to remove
Returns: boolean - true if the node was removed, false if it wasn’t in the list

removeMany

Removes multiple nodes from the list.
Array<LLNode<Node>>
Array of nodes to remove
Returns: number - The number of nodes actually removed

swap

Swaps the positions of two nodes in the list.
LLNode<Node>
First node
LLNode<Node>
Second node
Returns: void

move

Moves a node to a new position in the list.
LLNode<Node>
The node to move
LLNode<Node> | null
The node after which to insert, or null to move to the beginning
Returns: void

clear

Removes all nodes from the list. Returns: void

find

Finds the first node that matches a predicate.
(node: LLNode<Node>) => boolean
Predicate function
Returns: LLNode<Node> | null - The found node or null

batch

Batches multiple operations into a single update.
Fn
Callback containing operations to batch

reatomMap

Creates a derived linked list by mapping each node.
(node: LLNode<Node>) => T
Function to transform each node
object | string
Configuration options or name string
Returns: LinkedListDerivedAtom<LLNode<Node>, LLNode<T>>

Basic Usage

Advanced Usage

Task Management with Atoms

Drag and Drop List

Derived Views

Initialize from Snapshot

Notes

  • Each linked list has unique LL_PREV and LL_NEXT symbols, allowing nodes to exist in multiple lists
  • All mutations create structural updates efficiently through the linked list structure
  • The array property is computed and memoized for performance
  • batch should be used when performing multiple operations to reduce update overhead
  • Nodes must be objects or functions; primitive values are not supported
  • The key option enables efficient lookups by creating a reactive Map
  • Direct manipulation of node pointers is not recommended; use the provided methods