@cycle/run
- Version 5.7.0
- Published
- 94.8 kB
- 2 dependencies
- MIT license
Install
npm i @cycle/run
yarn add @cycle/run
pnpm add @cycle/run
Overview
The Cycle.js run() function to use with xstream
Index
Functions
function run
run: <D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>>( main: M, drivers: D) => DisposeFunction;
Takes a
main
function and circularly connects it to the given collection of driver functions.**Example:**
import run from '@cycle/run';const dispose = run(main, drivers);// ...dispose();The
main
function expects a collection of "source" streams (returned from drivers) as input, and should return a collection of "sink" streams (to be given to drivers). A "collection of streams" is a JavaScript object where keys match the driver names registered by thedrivers
object, and values are the streams. Refer to the documentation of each driver to see more details on what types of sources it outputs and sinks it receives.Parameter main
a function that takes
sources
as input and outputssinks
.Parameter drivers
an object where keys are driver names and values are driver functions. {Function} a dispose function, used to terminate the execution of the Cycle.js program, cleaning up resources used. run
function setup
setup: <D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>>( main: M, drivers: D) => CycleProgram<D, M>;
A function that prepares the Cycle application to be executed. Takes a
main
function and prepares to circularly connects it to the given collection of driver functions. As an output,setup()
returns an object with three properties:sources
,sinks
andrun
. Only whenrun()
is called will the application actually execute. Refer to the documentation ofrun()
for more details.**Example:**
import {setup} from '@cycle/run';const {sources, sinks, run} = setup(main, drivers);// ...const dispose = run(); // Executes the application// ...dispose();Parameter main
a function that takes
sources
as input and outputssinks
.Parameter drivers
an object where keys are driver names and values are driver functions. {Object} an object with three properties:
sources
,sinks
andrun
.sources
is the collection of driver sources,sinks
is the collection of driver sinks, these can be used for debugging or testing.run
is the function that once called will execute the application. setup
function setupReusable
setupReusable: <D extends Drivers>(drivers: D) => Engine<D>;
A partially-applied variant of setup() which accepts only the drivers, and allows many
main
functions to execute and reuse this same set of drivers.Takes an object with driver functions as input, and outputs an object which contains the generated sources (from those drivers) and a
run
function (which in turn expects sinks as argument). Thisrun
function can be called multiple times with different arguments, and it will reuse the drivers that were passed tosetupReusable
.**Example:**
import {setupReusable} from '@cycle/run';const {sources, run, dispose} = setupReusable(drivers);// ...const sinks = main(sources);const disposeRun = run(sinks);// ...disposeRun();// ...dispose(); // ends the reusability of driversParameter drivers
an object where keys are driver names and values are driver functions. {Object} an object with three properties:
sources
,run
anddispose
.sources
is the collection of driver sources,run
is the function that once called with 'sinks' as argument, will execute the application, tying together sources with sinks.dispose
terminates the reusable resources used by the drivers. Note also thatrun
returns a dispose function which terminates resources that are specific (not reusable) to that run. setupReusable
Interfaces
interface CycleProgram
interface CycleProgram< D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>> {}
Type Aliases
type DevToolEnabledSource
type DevToolEnabledSource = { _isCycleSource: string;};
type DisposeFunction
type DisposeFunction = () => void;
type Driver
type Driver<Si, So> = Si extends void ? () => So : (stream: Si) => So;
type Drivers
type Drivers = { [name: string]: Driver<Stream<any>, any | void>;};
type FantasyObservable
type FantasyObservable<T> = { subscribe(observer: FantasyObserver<T>): FantasySubscription;};
type FantasyObserver
type FantasyObserver<T> = { next(x: T): void; error(err: any): void; complete(c?: any): void;};
type FantasySubscription
type FantasySubscription = { unsubscribe(): void;};
type GetValidInputs
type GetValidInputs<D extends Driver<any, any>> = D extends Driver<infer S, any> ? S extends Stream<infer T> ? T : never : never;
type Main
type Main = (...args: Array<any>) => any;
type MatchingDrivers
type MatchingDrivers<D extends Drivers, M extends Main> = Drivers & { [k in string & keyof Sinks<M>]: | (() => Sources<D>[k]) | (( si: Stream<WidenStream<ToStream<Sinks<M>[k]>, GetValidInputs<D[k]>>> ) => Sources<D>[k]);};
type MatchingMain
type MatchingMain<D extends Drivers, M extends Main> = | (Main & { (so: Sources<D>): Sinks<M>; }) | (Main & { (): Sinks<M>; });
type SinkProxies
type SinkProxies<Si> = { [P in keyof Si]: Stream<any>;};
type Sinks
type Sinks<M extends Main> = ReturnType<M>;
type Sources
type Sources<D extends Drivers> = { [k in keyof D]: ReturnType<D[k]>;};
type WidenStream
type WidenStream<S, U> = S extends Stream<infer T> ? (T extends U ? U : never) : any;
Package Files (2)
Dependencies (2)
Dev Dependencies (9)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@cycle/run
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@cycle/run)
- HTML<a href="https://www.jsdocs.io/package/@cycle/run"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2172 ms. - Missing or incorrect documentation? Open an issue for this package.