Skip to main content
Home
This release is 13 versions behind 3.0.2 — the latest version of @lostinmind/c3-project. Jump to latest
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
23%
Published
a month ago (1.2.3)
import { C3EventsHandler } from "./eventsHandler.ts"; type TickHandler = () => void export abstract class C3App extends C3EventsHandler<RuntimeEventMap> { readonly runtime: IRuntime; private readonly tickHandlers = new Set<TickHandler>(); constructor(runtime: IRuntime) { super(runtime); this.runtime = runtime; this.on('beforeprojectstart', () => this.beforeStart()); this.on('afterprojectstart', () => this.onStart()); this.on('tick', () => this.#onTick()); } protected abstract beforeStart(): void; protected abstract onStart(): void; onTick(handler: TickHandler) { this.tickHandlers.add(handler); return () => { this.tickHandlers.delete(handler); } } addInstances<T extends Record<keyof IConstructProjectObjects, Function>>(instances: Partial<T>) { for (const [objectName, klass] of Object.entries(instances)) { //@ts-ignore this.runtime.objects[objectName as keyof IConstructProjectObjects].setInstanceClass(klass); } } addPromises(promises: Promise<void>[]) { for (const promise of promises) { this.runtime.sdk.addLoadPromise(promise); } } #onTick() { for (const handler of this.tickHandlers) { handler(); } } }