UNPKG

cyclejs-utils

Version:

A few utility functions for dealing with merging of sinks

54 lines (53 loc) 2.59 kB
import { Stream } from 'xstream'; import { Instances, Lens } from '@cycle/state'; declare type MergeArguments<T, K extends string = 'whatever'> = { [Key in K]: T extends (first: infer A) => void ? A : MergeOnePlus<T, K>; }[K]; declare type MergeOnePlus<T, K extends string> = { [Key in K]: T extends (first: infer A, ...args: infer U) => void ? A & MergeArguments<(...args: U) => void, K> : never; }[K]; declare type IntoSignature<T extends unknown[]> = (...args: T) => void; declare type MergeTupleMembers<T extends unknown[]> = MergeArguments<IntoSignature<T>>; export declare type MergeExceptions<Si> = { [k in keyof Si]?: (s: Si[k][]) => Si[k]; }; /** * Applies xs.merge to all sinks in the array * @param {Sinks[]} sinks the sinks to be merged * @param {MergeExceptions} exceptions a dictionary of special channels, e.g. DOM * @return {Sinks} the new unified sink */ export declare function mergeSinks<T extends [any, ...any[]]>(sinks: T, exceptions?: MergeExceptions<MergeTupleMembers<T>>): MergeTupleMembers<T>; export declare type PickMergeExceptions = { [k: string]: (ins: Instances<any>) => Stream<any>; }; /** * Just like mergeSinks, but for onionify collections * @see mergeSinks */ export declare function pickMergeSinks(driverNames: string[], exceptions?: PickMergeExceptions): (ins: Instances<any>) => any; /** * Extracts the sinks from a Stream of Sinks * @param {Stream<Sinks>} sinks$ * @param {string[]} driverNames the names of all drivers that are possibly in the stream, it's best to use Object.keys() on your driver object * @return {Sinks} A sinks containing the streams of the last emission in the sinks$ */ export declare function extractSinks<Si>(sinks$: Stream<Si>, driverNames: string[]): { [k in keyof Si]-?: Si[k]; }; /** * Can be used to load a component lazy (with webpack code splitting) * @param {() => any} moduleLoader A function like `() => import('./myModule')` * @param {string[]} driverNames The names of the drivers the lazy component uses * @param {string} name The name of the export. For loading a default export simply ignore * @return {Component} A dummy that loads the actual component */ export declare function loadAsync(moduleLoader: () => Promise<any>, driverNames: string[], name?: string): (s: any) => any; /** * Composes two lenses to one * @param {Lens<A, B>} outer * @param {Lens<B, C>} inner * @return {Lens<A, C>} composed lens */ export declare function composeLenses<A, B, C>(outer: Lens<A, B>, inner: Lens<B, C>): Lens<A, C>; export {};