Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @swim/streamlet

@swim/streamlet

package documentation chat

@swim/streamlet provides a stateful, streaming component model. Streamlets are stateful application components that continuously consume input state from streaming inlets, and continuously produce output state on streaming outlets. @swim/streamlet is written in TypeScript, but can be used from either TypeScript or JavaScript. @swim/streamlet is part of the @swim/core framework.

Overview

@swim/streamlet defines a model for continuous stateful computations that consume many streaming input states, and produce many streaming output states. The streamlet model facilitates dynamic binding of streaming application components to their inputs and outputs, and provides a precise, rate decoupled, backpressure regulated, re-evaluation model for reconciling the state of streamlet components after their transitively dependent input states change.

Streamlets are general purpose programming constructs; they are not restricted to modelling pure, data parallel functions. Unlinke Spark RDDs, or Flink Datasets, Streamlets can encapsulate arbitrary streaming business logic. And unlike Reactive Streams, which are purely demand driven, Streamlets model both supply and demand signals, enabling significantly optimized subgraph re-evaluation when sets of input states change concurrently.

Inlets, Outlets, and Streamlets

The streamlet programming model introduces three key concepts: inlets, outlets, and streamlets.

  • Inlet – a consumer of state changes.
  • Outlet – a producer of state changes.
  • Streamlet – a stateful component with zero or more named input outlets, and zero or more named output inlets.

Additional derivative Inlet and Outlet types provide specialized interfaces for structured input and output states.

  • MapInlet – a consumer of keyed state changes, i.e. updates to a key-value map.
  • MapOutlet – a producer of keyed state changes, i.e. updates to a key-value map.

Combinators

Outlets, being sources of state, define functional combinators, such as map, filter, and reduce, that produce new, transformed outlets. The Streamlet model enables ultra efficient recomputation of combinators. The reduce combinator, for example, memoizes partial reduction products in a b-tree, enabling log-time updates to its reduced state when any given input key changes.

Installation

npm

For an npm-managed project, npm install @swim/streamlet to make it a dependency. TypeScript sources will be installed into node_modules/@swim/streamlet/main. Transpiled JavaScript and TypeScript definition files install into node_modules/@swim/streamlet/lib/main. And a pre-built UMD script can be found in node_modules/@swim/streamlet/dist/main/swim-streamlet.js.

Browser

Browser applications can load swim-core.js, which comes bundled with the @swim/streamlet library, directly from the swimOS CDN.

<!-- Development -->
<script src="https://cdn.swimos.org/js/latest/swim-core.js"></script>

<!-- Production -->
<script src="https://cdn.swimos.org/js/latest/swim-core.min.js"></script>

Alternatively, the standalone swim-system.js script may be loaded from the swimOS CDN, which bundles @swim/streamlet together with all other @swim/system libraries.

<!-- Development -->
<script src="https://cdn.swimos.org/js/latest/swim-system.js"></script>

<!-- Production -->
<script src="https://cdn.swimos.org/js/latest/swim-system.min.js"></script>

Usage

ES6/TypeScript

@swim/streamlet can be imported as an ES6 module from TypeScript and other ES6-compatible environments.

import * as streamlet from "@swim/streamlet";

CommonJS/Node.js

@swim/streamlet can also be used as a CommonJS module in Node.js applications.

var streamlet = require("@swim/streamlet");

Browser

When loaded by a web browser, the swim-core.js script adds all @swim/streamlet library exports to the global swim namespace.

The swim-system.js script also adds all @swim/streamlet library exports to the global swim namespace, making it a drop-in replacement for swim-core.js when additional @swim/system libraries are needed.

Index

Type aliases

FilterFieldsFunction

FilterFieldsFunction<K, V>: (key: K, value: V) => boolean

Type parameters

  • K

  • V

Type declaration

    • (key: K, value: V): boolean
    • Parameters

      • key: K
      • value: V

      Returns boolean

InletType

InletType: "value" | "map"

InoutletType

InoutletType: "value" | "map"

MapFieldValuesFunction

MapFieldValuesFunction<K, VI, VO>: (key: K, value: VI) => VO

Type parameters

  • K

  • VI

  • VO

Type declaration

    • (key: K, value: VI): VO
    • Parameters

      • key: K
      • value: VI

      Returns VO

MapValueFunction

MapValueFunction<I, O>: (value: I) => O

Type parameters

  • I

  • O

Type declaration

    • (value: I): O
    • Parameters

      • value: I

      Returns O

OutletType

OutletType: "value" | "map"

WatchFieldsFunction

WatchFieldsFunction<K, V>: (key: K, value: V) => void

Type parameters

  • K

  • V

Type declaration

    • (key: K, value: V): void
    • Parameters

      • key: K
      • value: V

      Returns void

WatchValueFunction

WatchValueFunction<I>: (value: I) => void

Type parameters

  • I

Type declaration

    • (value: I): void
    • Parameters

      • value: I

      Returns void

Functions

In

  • In(name: string): PropertyDecorator
  • In(options: InletOptions): PropertyDecorator
  • In(target: unknown, key: string): void

Inout

  • Inout(name: string): PropertyDecorator
  • Inout(options: InoutletOptions): PropertyDecorator
  • Inout(target: unknown, key: string): void

Out

  • Out(name: string): PropertyDecorator
  • Out(options: OutletOptions): PropertyDecorator
  • Out(target: unknown, key: string): void