UNPKG

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