domco

Modules

On this page

Type Aliases

Block

Ƭ Block<D>: (window: DOMWindow, data?: D) => any

  • Import and utilize a block inside of a Build function
  • Wrapper function to provide the window in other imported modules

Example

// src/lib/blocks/myBlock.ts
import type { Block } from "domco";

export const myBlock: Block = async ({ document }) => {
    // modify the document
}

// src/+config.ts
import { type Config, addBlocks } from "domco";
import { myBlock } from "$lib/blocks/myBlock";

export const config: Config = {
    build: async (window) => {
        await myBlock(window);

        // or alternatively if you have many blocks
        await addBlocks(window, [myBlock, ...]);
    }
};

Type parameters

NameType
Dundefined

Type declaration

▸ (window, data?): any

Parameters
NameType
windowDOMWindow
data?D
Returns

any

Defined in

types/index.ts:55


Build

Ƭ Build<P>: (window: DOMWindow, context: BuildContext<P[number]>) => any

Type parameters

NameType
Pextends Params = Params

Type declaration

▸ (window, context): any

Parameters
NameType
windowDOMWindow
contextBuildContext<P[number]>
Returns

any

Defined in

types/index.ts:3


BuildContext

Ƭ BuildContext<P>: Object

Context about the current page to utilize during the build.

Type parameters

Name
P

Type declaration

NameTypeDescription
paramsPThe current route’s parameters. Example ts { slug: "my-post" }
routestringThe route as a string, for example: /posts/[slug]/

Defined in

types/index.ts:16


Config

Ƭ Config<P>: Object

Type parameters

NameType
Pextends Params = Params

Type declaration

NameTypeDescription
build?Build<P>- utilized in +config files. - This function runs at build time on the corresponding .html pages. Example ts // src/+config.ts import type { Config } from "domco"; export const config: Config = { build: async ({ document }) => { // modify the contents of `./index.html` const p = document.createElement("p"); p.textContent = "A server rendered paragraph."; document.body.appendChild(p); } };
layout?stringString of html with ato render the content into.
layoutBuild?Build<P>A build function that applies to the current page, and all nested pages.
params?PProvide the possible parameters for the current route. Example ts [{ slug: "my-post" }]

Defined in

types/index.ts:69


Params

Ƭ Params: ReadonlyArray<Record<string, string>>

Defined in

types/index.ts:67

Functions

addBlocks

addBlocks(window, blocks): Promise<PromiseSettledResult<any>[]>

A helper function that runs an array of blocks asynchronously with Promise.allSettled, passing the window and optionally data into each block

Parameters

NameTypeDescription
windowDOMWindowthe Window object to be passed into each block
blocks(Block<any> | { block: Block<any> ; data: any })[]an array of blocks

Returns

Promise<PromiseSettledResult<any>[]>

an array containing the results of each block

Example

// src/index.build.ts
import { type Config, addBlocks } from "domco";
import { myBlock, anotherBlock } from "$lib/blocks/myBlocks";

export const config: Config = {
    build: async (window) => {
        const results = await addBlocks(window, [myBlock, anotherBlock]);
    },
};

Defined in

helpers/addBlocks/index.ts:26