Skip to content

Stack API

Stack is a CRDT-backed ordered collection of tokens over a Chronicle.

new Stack(session, tokens?, options?)
Stack.fromDocument(session)

options supports seed? and autoInit?. The facade exposes size, tokens, drawn, discards, and canReset getters, plus toJSON().

Mutating methods include draw(n?), drawMany(n), shuffle(seed?), reset(), burn(n?), discard(token), cut(position?, options?), insertAt(token, index), removeAt(index), swap(i, j), and reverseRange(i, j). They write through the shared Chronicle and emit domain events.

For application code using an Engine, prefer the corresponding stack:* dispatch actions so history, policies, and Engine events remain consistent.