01BasicsRuns offline

Component

Define a component and run it as a plain function.

flowchart LR
  input(["'hello, astack'"]) --> U[Uppercase.run] --> output(["'HELLO, ASTACK'"])

What it shows

  • A component extends Component and overrides run().
  • run() is standalone mode. The same class also works inside a pipeline, as the next example shows.

The program

examples/component/index.ts
import { Component } from '@astack-tech/core';

/**
 * A component is a class with input and output ports.
 * `run()` is its standalone mode: call it like a function.
 */
class Uppercase extends Component {
  constructor() {
    super({});
  }

  override run(text: unknown): string {
    return String(text).toUpperCase();
  }
}

const uppercase = new Uppercase();

console.log(uppercase.run('hello, astack'));
// HELLO, ASTACK

Run it

pnpm install && pnpm build

pnpm --filter @astack-examples/component start
CONCEPTComponentsThe Component class, its ports, and its two execution modes.View the folder on GitHub