Skip to content

ServiceClass

Description

Service class builder.

Services are classes that can be exported in the dreamkit entry and allow you to initialize configurations that remain alive throughout the lifecycle of the application.

If you edit a service in development mode, that service will be restarted.

Import

import { ServiceClass } from "dreamkit";

Definition

declare const ServiceClass: {
(self: object): {
new (): {
onStart(): undefined | (() => any);
onStop(): any;
};
};
};

Examples

Basic usage

import { $route, ServiceClass } from "dreamkit";
export class AppService extends ServiceClass({}) {
onStart() {
console.log("started"); // edit this line and save
return () => console.log("stopped");
}
}
export const homeRoute = $route.path("/").create(() => {
return <>hello world</>;
});