Navigation and bookmarks
Navigation
Section titled “Navigation”These functions move the reader through their history.
stepForward
Section titled “stepForward”stepForward moves the reader forward one step through their history. If they’re already at the latest step, it does nothing.
stepForward(): Promise<void>Example
await stepForward();stepBack
Section titled “stepBack”stepBack moves the reader back one step through their history, and restores the state from that step.
stepBack(): Promise<void>Example
await stepBack();isRewinding
Section titled “isRewinding”isRewinding returns true if the reader is currently stepping backward through the story.
isRewinding(): booleanExample
const rewinding = isRewinding();Bookmarks
Section titled “Bookmarks”A bookmark is a saved game. It captures the novel’s state so the reader can come back to it later.
Bookmarks save the state from the last committed beat. Any state changed after that isn’t included. See when to change state.
interface Bookmark { id: string; image: null | string; time: number; type: "auto" | "quick" | "user";}| Field | Description |
|---|---|
id | Identifies the bookmark. Saving a bookmark replaces any bookmark with the same ID. |
image | A thumbnail of the saved scene, as a data URL, or null if there’s no image. |
time | When the bookmark was saved, in milliseconds since the epoch. |
type | "auto" for the auto save, "quick" for a quicksave, or "user" for a save the reader chose. |
Every commit saves the reader’s place as the auto save: a bookmark with the ID auto and the type "auto".
getBookmarks
Section titled “getBookmarks”getBookmarks returns every saved bookmark for the current novel, newest first.
getBookmarks(): Promise<Array<Bookmark>>Example
const bookmarks = await getBookmarks();saveBookmark
Section titled “saveBookmark”saveBookmark saves a bookmark with the state from the last committed beat. If a bookmark with the same id already exists, it replaces that one.
saveBookmark(bookmark: Bookmark): Promise<void>Example
await saveBookmark({ id: "slot-1", image: thumbnailDataUrl, time: Date.now(), type: "user",});loadBookmark
Section titled “loadBookmark”loadBookmark loads a saved bookmark and restores the novel to that point.
loadBookmark(bookmark: Bookmark): Promise<void>Example
const bookmarks = await getBookmarks();await loadBookmark(bookmarks[0]);