Merge pull request #18572 from HitoriSensei/kefir-update

Updates for Kefir.js
This commit is contained in:
Nathan Shively-Sanders
2017-09-06 15:49:27 -07:00
committed by GitHub
+49 -26
View File
@@ -1,10 +1,14 @@
// Type definitions for Kefir 3.3.0
// Type definitions for Kefir 3.7.3
// Project: http://rpominov.github.io/kefir/
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
// Piotr Hitori Bosak <https://github.com/HitoriSensei>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="node" />
export type ValueOfAnObservable<T extends Observable<any, any>> = T[''];
export interface Subscription {
unsubscribe(): void;
closed: boolean; // Actually, `readonly` but it's avaiable in tsc starting with 2.0.0
@@ -28,19 +32,25 @@ export interface Observer<T, S> {
}
export interface Observable<T, S> {
'': T; // TypeScript hack to enable value unwrapping for combine/flatMap
toProperty(getCurrent?: () => T): Property<T, S>;
// Subscribe / add side effects
onValue(callback: (value: T) => void): void;
offValue(callback: (value: T) => void): void;
onError(callback: (error: S) => void): void;
offError(callback: (error: S) => void): void;
onEnd(callback: () => void): void;
offEnd(callback: () => void): void;
onAny(callback: (event: Event<T | S>) => void): void;
offAny(callback: (event: Event<T | S>) => void): void;
log(name?: string): void;
offLog(name?: string): void;
onValue(callback: (value: T) => void): this;
offValue(callback: (value: T) => void): this;
onError(callback: (error: S) => void): this;
offError(callback: (error: S) => void): this;
onEnd(callback: () => void): this;
offEnd(callback: () => void): this;
onAny(callback: (event: Event<T | S>) => void): this;
offAny(callback: (event: Event<T | S>) => void): this;
log(name?: string): this;
spy(name?: string): this;
offLog(name?: string): this;
offSpy(name?: string): this;
flatten<U>(transformer?: (value: T) => U[]): Stream<U, S>;
toPromise(PromiseConstructor?: any): any;
toPromise(): Promise<T>;
toPromise<W extends PromiseLike<T>>(PromiseConstructor: () => W): W;
toESObservable(): any;
// This method is designed to replace all other methods for subscribing
observe(params: Observer<T, S>): Subscription;
@@ -49,11 +59,11 @@ export interface Observable<T, S> {
onError?: (error: S) => void,
onEnd?: () => void
): Subscription;
setName(source: Observable<any, any>, selfName: string): this;
setName(selfName: string): this;
}
export interface Stream<T, S> extends Observable<T, S> {
toProperty(getCurrent?: () => T): Property<T, S>;
// Modify an stream
map<U>(fn: (value: T) => U): Stream<U, S>;
filter(predicate?: (value: T) => boolean): Stream<T, S>;
@@ -64,7 +74,8 @@ export interface Stream<T, S> extends Observable<T, S> {
skipWhile(predicate?: (value: T) => boolean): Stream<T, S>;
skipDuplicates(comparator?: (a: T, b: T) => boolean): Stream<T, S>;
diff(fn?: (prev: T, next: T) => T, seed?: T): Stream<T, S>;
scan(fn: (prev: T, next: T) => T, seed?: T): Stream<T, S>;
scan<W>(fn: (prev: T | W, next: T) => W): Stream<W, S>;
scan<W>(fn: (prev: W, next: T) => W, seed: W): Stream<W, S>;
delay(wait: number): Stream<T, S>;
throttle(wait: number, options?: { leading?: boolean, trailing?: boolean }): Stream<T, S>;
debounce(wait: number, options?: { immediate: boolean }): Stream<T, S>;
@@ -85,19 +96,21 @@ export interface Stream<T, S> extends Observable<T, S> {
bufferWithTimeOrCount(interval: number, count: number, options?: { flushOnEnd: boolean }): Stream<T[], S>;
transduce<U>(transducer: any): Stream<U, S>;
withHandler<U, V>(handler: (emitter: Emitter<U, S>, event: Event<T | S>) => void): Stream<U, S>;
// Combine streams
combine<U, V, W>(otherObs: Stream<U, V>, combinator?: (value: T, ...values: U[]) => W): Stream<W, S | V>;
zip<U, V, W>(otherObs: Stream<U, V>, combinator?: (value: T, ...values: U[]) => W): Stream<W, S | V>;
merge<U, V>(otherObs: Stream<U, V>): Stream<T | U, S | V>;
concat<U, V>(otherObs: Stream<U, V>): Stream<T | U, S | V>;
flatMap<U, V>(transform: (value: T) => Stream<U, V>): Stream<U, V>;
flatMap<X extends T & Property<T, any>>(): Stream<ValueOfAnObservable<X>, any>;
flatMapLatest<U, V>(fn: (value: T) => Stream<U, V>): Stream<U, V>;
flatMapLatest<X extends T & Property<T, any>>(): Stream<ValueOfAnObservable<X>, any>;
flatMapFirst<U, V>(fn: (value: T) => Stream<U, V>): Stream<U, V>;
flatMapFirst<X extends T & Property<T, any>>(): Stream<ValueOfAnObservable<X>, any>;
flatMapConcat<U, V>(fn: (value: T) => Stream<U, V>): Stream<U, V>;
flatMapConcat<X extends T & Property<T, any>>(): Stream<ValueOfAnObservable<X>, any>;
flatMapConcurLimit<U, V>(fn: (value: T) => Stream<U, V>, limit: number): Stream<U, V>;
flatMapErrors<U, V>(transform: (error: S) => Stream<U, V>): Stream<U, V>;
// Combine two streams
filterBy<U>(otherObs: Observable<boolean, U>): Stream<T, S>;
sampledBy<U, V, W>(otherObs: Observable<U, V>, combinator?: (a: T, b: U) => W): Stream<W, S>;
@@ -110,7 +123,6 @@ export interface Stream<T, S> extends Observable<T, S> {
export interface Property<T, S> extends Observable<T, S> {
changes(): Stream<T, S>;
// Modify an property
map<U>(fn: (value: T) => U): Property<U, S>;
filter(predicate?: (value: T) => boolean): Property<T, S>;
@@ -141,19 +153,20 @@ export interface Property<T, S> extends Observable<T, S> {
bufferWithTimeOrCount(interval: number, count: number, options?: { flushOnEnd: boolean }): Property<T[], S>;
transduce<U>(transducer: any): Property<U, S>;
withHandler<U, V>(handler: (emitter: Emitter<T, S>, event: Event<T | S>) => void): Property<U, S>;
// Combine properties
combine<U, V, W>(otherObs: Property<U, V>, combinator?: (value: T, ...values: U[]) => W): Property<W, S | V>;
zip<U, V, W>(otherObs: Property<U, V>, combinator?: (value: T, ...values: U[]) => W): Property<W, S | V>;
merge<U, V>(otherObs: Property<U, V>): Property<T | U, S | V>;
concat<U, V>(otherObs: Property<U, V>): Property<T | U, S | V>;
flatMap<U, V>(transform: (value: T) => Property<U, V>): Property<U, V>;
flatMap<X extends T & Property<T, any>>(): Property<ValueOfAnObservable<X>, any>;
flatMapLatest<U, V>(fn: (value: T) => Property<U, V>): Property<U, V>;
flatMapLatest<X extends T & Property<T, any>>(): Property<ValueOfAnObservable<X>, any>;
flatMapFirst<U, V>(fn: (value: T) => Property<U, V>): Property<U, V>;
flatMapFirst<X extends T & Property<T, any>>(): Property<ValueOfAnObservable<X>, any>;
flatMapConcat<U, V>(fn: (value: T) => Property<U, V>): Property<U, V>;
flatMapConcurLimit<U, V>(fn: (value: T) => Property<U, V>, limit: number): Property<U, V>;
flatMapErrors<U, V>(transform: (error: S) => Property<U, V>): Property<U, V>;
// Combine two properties
filterBy<U>(otherObs: Observable<boolean, U>): Property<T, S>;
sampledBy<U, V, W>(otherObs: Observable<U, V>, combinator?: (a: T, b: U) => W): Property<W, S>;
@@ -165,8 +178,8 @@ export interface Property<T, S> extends Observable<T, S> {
}
export interface ObservablePool<T, S> extends Observable<T, S> {
plug(obs: Observable<T, S>): void;
unPlug(obs: Observable<T, S>): void;
plug(obs: Observable<T, S>): this;
unPlug(obs: Observable<T, S>): this;
}
export interface Event<T> {
@@ -197,11 +210,21 @@ export declare function fromESObservable<T, S>(observable: any): Stream<T, S>
// Create a property
export declare function constant<T>(value: T): Property<T, never>;
export declare function constantError<T>(error: T): Property<never, T>;
export declare function fromPromise<T, S>(promise: any): Property<T, S>;
export declare function fromPromise<T, S>(promise: Promise<T>): Property<T, S>;
// Combine observables
export declare function combine<T, S, U>(obss: Observable<T, S>[], passiveObss: Observable<T, S>[], combinator?: (...values: T[]) => U): Observable<U, S>;
export declare function combine<T, S, U>(obss: Observable<T, S>[], combinator?: (...values: T[]) => U): Observable<U, S>;
export declare function combine<T, S, U>(obss: Observable<T, S>[], passiveObss: Observable<T, S>[], combinator?: (...values: T[]) => U): Stream<U, S>;
export declare function combine<T, S, U>(obss: Observable<T, S>[], combinator: (...values: T[]) => U): Stream<U, S>;
export declare function combine<T extends { [name: string]: Observable<any, any> }>(obss: T): Stream<{ [P in keyof T]: ValueOfAnObservable<T[P]> }, any>;
export declare function combine<T extends [Observable<any, any>], P extends keyof T>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>], any>;
export declare function combine<T extends [Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>, ValueOfAnObservable<T[2]>, ValueOfAnObservable<T[3]>, ValueOfAnObservable<T[4]>, ValueOfAnObservable<T[5]>, ValueOfAnObservable<T[6]>, ValueOfAnObservable<T[7]>], any>;
export declare function combine<T extends [Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>, ValueOfAnObservable<T[2]>, ValueOfAnObservable<T[3]>, ValueOfAnObservable<T[4]>, ValueOfAnObservable<T[5]>, ValueOfAnObservable<T[6]>], any>;
export declare function combine<T extends [Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>, ValueOfAnObservable<T[2]>, ValueOfAnObservable<T[3]>, ValueOfAnObservable<T[4]>, ValueOfAnObservable<T[5]>], any>;
export declare function combine<T extends [Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>, ValueOfAnObservable<T[2]>, ValueOfAnObservable<T[3]>, ValueOfAnObservable<T[4]>], any>;
export declare function combine<T extends [Observable<any, any>, Observable<any, any>, Observable<any, any>, Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>, ValueOfAnObservable<T[2]>, ValueOfAnObservable<T[3]>], any>;
export declare function combine<T extends [Observable<any, any>, Observable<any, any>, Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>, ValueOfAnObservable<T[2]>], any>;
export declare function combine<T extends [Observable<any, any>, Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>, ValueOfAnObservable<T[1]>], any>;
export declare function combine<T extends [Observable<any, any>]>(obss: T): Stream<[ValueOfAnObservable<T[0]>], any>;
export declare function combine<T extends never[]>(obss: T): Stream<never, never>;
export declare function zip<T, S, U>(obss: Observable<T, S>[], passiveObss?: Observable<T, S>[], combinator?: (...values: T[]) => U): Observable<U, S>;
export declare function merge<T, S>(obss: Observable<T, S>[]): Observable<T, S>;
export declare function concat<T, S>(obss: Observable<T, S>[]): Observable<T, S>;