@web-engine-dev/scheduler / defineSystem
Function: defineSystem()
defineSystem<
TContext>(id,fn):SystemBuilder<TContext>
Creates a system builder for fluent system definition.
Provides a chainable API for configuring system metadata including stage, dependencies, labels, parallelization, and run conditions.
Type Parameters
TContext
TContext = unknown
Parameters
id
System identifier (string or Symbol)
fn
SystemFn<TContext>
System function to execute
Returns
SystemBuilder<TContext>
A SystemBuilder instance
Example
typescript
// Basic usage
const movement = defineSystem('movement', (ctx) => {
for (const entity of ctx.world.query(Position, Velocity)) {
entity.get(Position).x += entity.get(Velocity).x * ctx.deltaTime;
}
})
.inStage(CoreStages.UPDATE)
.after('input')
.build();
// Full example with all options
const physics = defineSystem<GameContext>('physics', updatePhysics)
.inStage(CoreStages.UPDATE)
.after('input')
.before('render')
.label('physics', 'simulation')
.parallel()
.runIf((ctx) => !ctx.isPaused)
.build();