Skip to content

Runtime Services ​

Picard.js comes with a set of services that can be extended to provide more or augmented functionality.

Service Definitions ​

Right now the following extensible services exist:

Service Key StructureExampleInterfaceNotes
framework.{type}framework.reactConverterService
format.{name}format.moduleContainerService
slotRel.{name}slotRel.routerSlotBehaviorService
part.{name}part.stylePartServiceSSR only

Built-in services can be replaced, too. Everything passed in the services option overrides the default service with the same key, e.g., esm (evaluating ES modules), platform (loading scripts, modules, and JSON), or events. Each service is given as a function receiving the dependency injector and returning the service instance:

js
initializePicard({
  feed,
  services: {
    // e.g., in unit tests: import ES modules via the test runner
    esm: () => ({
      load(url, depMap, parent) {
        return import(toLocalFile(url));
      },
    }),
  },
});

👉 The Vitest sample replaces the esm service to run Native Federation micro frontends in jsdom and happy-dom.

Interfaces ​

ts
interface ConverterService {
  convert(component: any, opts: any): ComponentLifecycle;
}

For an explanation of the ComponentLifecycle see Generic component Lifecycle.

ts
interface ContainerService {
  createContainer(details: any): Promise<ComponentGetter>;
}
ts
interface SlotBehaviorService {
  apply(attribs: Record<string, string>): [name: string, data: any];
}
ts
interface PartService {
  getReplacement(document: Document, attribs: Record<string, string>): Promise<string>;
}

Released under the MIT License. Using an AI assistant? Point it to llms.txt.