Skip to content

Core

The core plugin starts your novel. It sets up the app, and serves your novel’s assets on the web.

Core’s commands mark the moments in your novel’s lifecycle: when it starts, when it’s shut down, and when it comes back. Most of them do nothing on their own. They’re there so other plugins can decorate them to run code at those moments.

Runs once, when the app starts.

init(): Promise<void>

Core’s init does nothing. Decorate it to run your plugin’s startup work.

Example
decorateCommand("init", (context, next) => {
console.log("Starting up...");
return next(context);
});

Runs when a suspended session is restored, like after your workspace is rebuilt during development.

resumeSession(): Promise<void>

Core’s resumeSession does nothing. Decorate it to restore anything you saved in suspendSession.

Example
decorateCommand("resumeSession", async (context, next) => {
await restoreMyState();
return next(context);
});

Runs when the current session is shut down, like when your workspace changes and the novel needs to reload.

suspendSession(ctx: SuspendSessionContext): Promise<void>
interface SuspendSessionContext {
reason: "workspace-updated";
}

reason says why the session is being suspended. Core’s suspendSession reloads the page. Decorate it to save anything you want back when resumeSession runs, and do your work before calling next.

Example
decorateCommand("suspendSession", async (context, next) => {
await saveMyState();
return next(context);
});