UNPKG

2.36 kBTypeScriptView Raw
1import { Stream, InternalProducer, InternalListener } from '../index';
2export interface FromDiagramOptions {
3 values?: Object;
4 errorValue?: any;
5 timeUnit?: number;
6}
7export declare class DiagramProducer implements InternalProducer<any> {
8 private diagram;
9 private values;
10 private errorVal;
11 private timeUnit;
12 private tasks;
13 constructor(diagram: string, opt?: FromDiagramOptions);
14 _start(out: InternalListener<any>): void;
15 private schedule;
16 _stop(): void;
17}
18/**
19 * Creates a real stream out of an ASCII drawing of a stream. Each string
20 * character represents an amount of time passed (by default, 20 milliseconds).
21 * `-` characters represent nothing special, `|` is a symbol to mark the
22 * completion of the stream, `#` is an error on the stream, and any other
23 * character is a "next" event.
24 *
25 * Example:
26 *
27 * ```js
28 * import fromDiagram from 'xstream/extra/fromDiagram'
29 *
30 * const stream = fromDiagram('--a--b---c-d--|')
31 *
32 * stream.addListener({
33 * next: (x) => console.log(x),
34 * error: (err) => console.error(err),
35 * complete: () => console.log('concat completed'),
36 * })
37 * ```
38 *
39 * The character `a` represent emission of the event `'a'`, a string. If you
40 * want to emit something else than a string, you need to provide those values
41 * in the options argument.
42 *
43 * Example:
44 *
45 * ```js
46 * import fromDiagram from 'xstream/extra/fromDiagram'
47 *
48 * const stream = fromDiagram('--a--b---c-d--|', {
49 * values: {a: 10, b: 20, c: 30, d: 40}
50 * })
51 *
52 * stream.addListener({
53 * next: (x) => console.log(x),
54 * error: (err) => console.error(err),
55 * complete: () => console.log('concat completed'),
56 * })
57 * ```
58 *
59 * That way, the stream will emit the numbers 10, 20, 30, 40. The `options`
60 * argument may also take `timeUnit`, a number to configure how many
61 * milliseconds does each represents, and `errorValue`, a value to send out as
62 * the error which `#` represents.
63 *
64 * @factory true
65 * @param {string} diagram A string representing a timeline of values, error,
66 * or complete notifications that should happen on the output stream.
67 * @param options An options object that allows you to configure some additional
68 * details of the creation of the stream.
69 * @return {Stream}
70 */
71export default function fromDiagram(diagram: string, options?: FromDiagramOptions): Stream<any>;