UNPKG

2.52 kBTypeScriptView Raw
1import { CycleSetup, DisposeFunction } from '@cycle/base';
2/**
3 * Takes a `main` function and circularly connects it to the given collection
4 * of driver functions.
5 *
6 * **Example:**
7 * ```js
8 * import {run} from '@cycle/rx-run';
9 * const dispose = Cycle.run(main, drivers);
10 * // ...
11 * dispose();
12 * ```
13 *
14 * The `main` function expects a collection of "source" Observables (returned
15 * from drivers) as input, and should return a collection of "sink" Observables
16 * (to be given to drivers). A "collection of Observables" is a JavaScript
17 * object where keys match the driver names registered by the `drivers` object,
18 * and values are the Observables. Refer to the documentation of each driver to
19 * see more details on what types of sources it outputs and sinks it receives.
20 *
21 * @param {Function} main a function that takes `sources` as input
22 * and outputs a collection of `sinks` Observables.
23 * @param {Object} drivers an object where keys are driver names and values
24 * are driver functions.
25 * @return {Function} a dispose function, used to terminate the execution of the
26 * Cycle.js program, cleaning up resources used.
27 * @function run
28 */
29export declare function run<Sources, Sinks>(main: (sources: Sources) => Sinks, drivers: {
30 [name: string]: Function;
31}): DisposeFunction;
32/**
33 * A function that prepares the Cycle application to be executed. Takes a `main`
34 * function and prepares to circularly connects it to the given collection of
35 * driver functions. As an output, `Cycle()` returns an object with three
36 * properties: `sources`, `sinks` and `run`. Only when `run()` is called will
37 * the application actually execute. Refer to the documentation of `run()` for
38 * more details.
39 *
40 * **Example:**
41 * ```js
42 * import Cycle from '@cycle/rx-run';
43 * const {sources, sinks, run} = Cycle(main, drivers);
44 * // ...
45 * const dispose = run(); // Executes the application
46 * // ...
47 * dispose();
48 * ```
49 *
50 * @param {Function} main a function that takes `sources` as input
51 * and outputs a collection of `sinks` Observables.
52 * @param {Object} drivers an object where keys are driver names and values
53 * are driver functions.
54 * @return {Object} an object with three properties: `sources`, `sinks` and
55 * `run`. `sources` is the collection of driver sources, `sinks` is the
56 * collection of driver sinks, these can be used for debugging or testing. `run`
57 * is the function that once called will execute the application.
58 * @function Cycle
59 */
60declare const Cycle: CycleSetup;
61export default Cycle;