Skip to content

Navigation and bookmarks

These functions move the reader through their history.

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 moves the reader back one step through their history, and restores the state from that step.

stepBack(): Promise<void>
Example
await stepBack();

isRewinding returns true if the reader is currently stepping backward through the story.

isRewinding(): boolean
Example
const rewinding = isRewinding();

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";
}
FieldDescription
idIdentifies the bookmark. Saving a bookmark replaces any bookmark with the same ID.
imageA thumbnail of the saved scene, as a data URL, or null if there’s no image.
timeWhen 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 returns every saved bookmark for the current novel, newest first.

getBookmarks(): Promise<Array<Bookmark>>
Example
const bookmarks = await getBookmarks();

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 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]);