Skip to content

Unit: Component

Jake edited this page Jul 20, 2018 · 2 revisions

Leverage Components

Components perform a specific interaction for a plugin. This could be handling one http request, managing a singular websocket connection, or reacting to a key press from a midi keyboard.

Leverage General Architecture

Component Unit

Component Interface

A valid component unit conforms to this interface:

interface ComponentUnit {
  is: 'component';
  type: string | string[];

  config?: {
    dependencies?: {
      plugins?: string[];
      services?: string[];
    }

    [key: string]: any;
  }

  [key: string]: any;
}

Component Actions

Often, a component will need to offer an entry point to perform some action. This is taken care of by a method with the same name as the component's type. For example, when creating a HTTP component, you may add a http() method for handling a request:

const component = {
  is: 'component',
  type: 'http',
  http (request, response) {
    // ...
  }
}
Clone this wiki locally