UNPKG

2.15 kBTypeScriptView Raw
1import { Stream } from 'xstream';
2export declare type FantasyObserver<T> = {
3 next(x: T): void;
4 error(err: any): void;
5 complete(c?: any): void;
6};
7export declare type FantasySubscription = {
8 unsubscribe(): void;
9};
10export declare type FantasyObservable<T> = {
11 subscribe(observer: FantasyObserver<T>): FantasySubscription;
12};
13export declare type DevToolEnabledSource = {
14 _isCycleSource: string;
15};
16export declare type SinkProxies<Si> = {
17 [P in keyof Si]: Stream<any>;
18};
19export declare type Driver<Si, So> = Si extends void ? (() => So) : ((stream: Si) => So);
20export declare type DisposeFunction = () => void;
21export declare type Drivers = {
22 [name: string]: Driver<Stream<any>, any | void>;
23};
24export declare type Main = (...args: Array<any>) => any;
25export declare type Sources<D extends Drivers> = {
26 [k in keyof D]: ReturnType<D[k]>;
27};
28export declare type Sinks<M extends Main> = ReturnType<M>;
29export declare type MatchingMain<D extends Drivers, M extends Main> = (Main & {
30 (so: Sources<D>): Sinks<M>;
31}) | (Main & {
32 (): Sinks<M>;
33});
34/**
35 * For whatever reason, this does not work with RxJS observables,
36 * this for this reason, `MatchingDrivers` has to be redefined
37 * in @cycle/rxjs-run-
38 */
39export declare type ToStream<S> = S extends FantasyObservable<infer T> ? Stream<T> : S;
40export declare type WidenStream<S, U> = S extends Stream<infer T> ? (T extends U ? U : never) : any;
41export declare type GetValidInputs<D extends Driver<any, any>> = D extends Driver<infer S, any> ? (S extends Stream<infer T> ? T : never) : never;
42export declare type MatchingDrivers<D extends Drivers, M extends Main> = Drivers & {
43 [k in string & keyof Sinks<M>]: (() => Sources<D>[k]) | ((si: Stream<WidenStream<ToStream<Sinks<M>[k]>, GetValidInputs<D[k]>>>) => Sources<D>[k]);
44};
45export interface CycleProgram<D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>> {
46 sources: Sources<D>;
47 sinks: Sinks<M>;
48 run(): DisposeFunction;
49}
50export interface Engine<D extends Drivers> {
51 sources: Sources<D>;
52 run<M extends MatchingMain<D, M>>(sinks: Sinks<M>): DisposeFunction;
53 dispose(): void;
54}
55
\No newline at end of file