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