From 9a99bb62415a8707f6229b484478cba564bdd364 Mon Sep 17 00:00:00 2001 From: "Piotr \"Hitori\" Bosak" Date: Wed, 2 Aug 2017 12:39:18 +0200 Subject: [PATCH 1/4] Updates for Kefir.js --- types/kefir/index.d.ts | 54 +++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/types/kefir/index.d.ts b/types/kefir/index.d.ts index 09917d7846..7d524b3dda 100644 --- a/types/kefir/index.d.ts +++ b/types/kefir/index.d.ts @@ -1,10 +1,13 @@ -// Type definitions for Kefir 3.3.0 +// Type definitions for Kefir 3.7.3 // Project: http://rpominov.github.io/kefir/ // Definitions by: Aya Morisawa +// Piotr Hitori Bosak // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// +export type ValueOfAnObservable> = T[''] + export interface Subscription { unsubscribe(): void; closed: boolean; // Actually, `readonly` but it's avaiable in tsc starting with 2.0.0 @@ -28,6 +31,9 @@ export interface Observer { } export interface Observable { + '': T // TypeScript hack to enable value unwrapping for combine/flatMap + + toProperty(getCurrent?: () => T): Property; // Subscribe / add side effects onValue(callback: (value: T) => void): void; offValue(callback: (value: T) => void): void; @@ -37,10 +43,13 @@ export interface Observable { offEnd(callback: () => void): void; onAny(callback: (event: Event) => void): void; offAny(callback: (event: Event) => void): void; - log(name?: string): void; - offLog(name?: string): void; + log(name?: string): this; + spy(name?: string): this; + offLog(name?: string): this; + offSpy(name?: string): this; flatten(transformer?: (value: T) => U[]): Stream; - toPromise(PromiseConstructor?: any): any; + toPromise(): Promise; + toPromise>(PromiseConstructor: () => W): W; toESObservable(): any; // This method is designed to replace all other methods for subscribing observe(params: Observer): Subscription; @@ -49,11 +58,11 @@ export interface Observable { onError?: (error: S) => void, onEnd?: () => void ): Subscription; + setName(source: Observable, selfName: string): this; + setName(selfName: string): this; } export interface Stream extends Observable { - toProperty(getCurrent?: () => T): Property; - // Modify an stream map(fn: (value: T) => U): Stream; filter(predicate?: (value: T) => boolean): Stream; @@ -64,7 +73,8 @@ export interface Stream extends Observable { skipWhile(predicate?: (value: T) => boolean): Stream; skipDuplicates(comparator?: (a: T, b: T) => boolean): Stream; diff(fn?: (prev: T, next: T) => T, seed?: T): Stream; - scan(fn: (prev: T, next: T) => T, seed?: T): Stream; + scan(fn: (prev: T | W, next: T) => W): Stream; + scan(fn: (prev: W, next: T) => W, seed: W): Stream; delay(wait: number): Stream; throttle(wait: number, options?: { leading?: boolean, trailing?: boolean }): Stream; debounce(wait: number, options?: { immediate: boolean }): Stream; @@ -85,19 +95,21 @@ export interface Stream extends Observable { bufferWithTimeOrCount(interval: number, count: number, options?: { flushOnEnd: boolean }): Stream; transduce(transducer: any): Stream; withHandler(handler: (emitter: Emitter, event: Event) => void): Stream; - // Combine streams combine(otherObs: Stream, combinator?: (value: T, ...values: U[]) => W): Stream; zip(otherObs: Stream, combinator?: (value: T, ...values: U[]) => W): Stream; merge(otherObs: Stream): Stream; concat(otherObs: Stream): Stream; flatMap(transform: (value: T) => Stream): Stream; + flatMap>(): Stream, any>; flatMapLatest(fn: (value: T) => Stream): Stream; + flatMapLatest>(): Stream, any>; flatMapFirst(fn: (value: T) => Stream): Stream; + flatMapFirst>(): Stream, any>; flatMapConcat(fn: (value: T) => Stream): Stream; + flatMapConcat>(): Stream, any>; flatMapConcurLimit(fn: (value: T) => Stream, limit: number): Stream; flatMapErrors(transform: (error: S) => Stream): Stream; - // Combine two streams filterBy(otherObs: Observable): Stream; sampledBy(otherObs: Observable, combinator?: (a: T, b: U) => W): Stream; @@ -110,7 +122,6 @@ export interface Stream extends Observable { export interface Property extends Observable { changes(): Stream; - // Modify an property map(fn: (value: T) => U): Property; filter(predicate?: (value: T) => boolean): Property; @@ -141,19 +152,20 @@ export interface Property extends Observable { bufferWithTimeOrCount(interval: number, count: number, options?: { flushOnEnd: boolean }): Property; transduce(transducer: any): Property; withHandler(handler: (emitter: Emitter, event: Event) => void): Property; - // Combine properties combine(otherObs: Property, combinator?: (value: T, ...values: U[]) => W): Property; zip(otherObs: Property, combinator?: (value: T, ...values: U[]) => W): Property; merge(otherObs: Property): Property; concat(otherObs: Property): Property; flatMap(transform: (value: T) => Property): Property; + flatMap>(): Property, any>; flatMapLatest(fn: (value: T) => Property): Property; + flatMapLatest>(): Property, any>; flatMapFirst(fn: (value: T) => Property): Property; + flatMapFirst>(): Property, any>; flatMapConcat(fn: (value: T) => Property): Property; flatMapConcurLimit(fn: (value: T) => Property, limit: number): Property; flatMapErrors(transform: (error: S) => Property): Property; - // Combine two properties filterBy(otherObs: Observable): Property; sampledBy(otherObs: Observable, combinator?: (a: T, b: U) => W): Property; @@ -197,11 +209,21 @@ export declare function fromESObservable(observable: any): Stream // Create a property export declare function constant(value: T): Property; export declare function constantError(error: T): Property; -export declare function fromPromise(promise: any): Property; - +export declare function fromPromise(promise: Promise): Property; // Combine observables -export declare function combine(obss: Observable[], passiveObss: Observable[], combinator?: (...values: T[]) => U): Observable; -export declare function combine(obss: Observable[], combinator?: (...values: T[]) => U): Observable; +export declare function combine(obss: Observable[], passiveObss: Observable[], combinator?: (...values: T[]) => U): Stream; +export declare function combine(obss: Observable[], combinator: (...values: T[]) => U): Stream; +export declare function combine }>(obss: T): Stream<{ [P in keyof T]: ValueOfAnObservable }, any>; +export declare function combine], P extends keyof T>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine, Observable, Observable, Observable, Observable, Observable, Observable, Observable]>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine, Observable, Observable, Observable, Observable, Observable, Observable]>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine, Observable, Observable, Observable, Observable, Observable]>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine, Observable, Observable, Observable, Observable]>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine, Observable, Observable, Observable]>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine, Observable, Observable]>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine, Observable]>(obss: T): Stream<[ValueOfAnObservable, ValueOfAnObservable], any>; +export declare function combine]>(obss: T): Stream<[ValueOfAnObservable], any>; +export declare function combine(obss: T): Stream; export declare function zip(obss: Observable[], passiveObss?: Observable[], combinator?: (...values: T[]) => U): Observable; export declare function merge(obss: Observable[]): Observable; export declare function concat(obss: Observable[]): Observable; From 9e257d00c79b28bd3c0a03f2fb69c6a60d6c896a Mon Sep 17 00:00:00 2001 From: "Piotr \"Hitori\" Bosak" Date: Wed, 2 Aug 2017 13:28:28 +0200 Subject: [PATCH 2/4] Fixed missing semicolon --- types/kefir/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/kefir/index.d.ts b/types/kefir/index.d.ts index 7d524b3dda..ea823f73ff 100644 --- a/types/kefir/index.d.ts +++ b/types/kefir/index.d.ts @@ -6,7 +6,7 @@ /// -export type ValueOfAnObservable> = T[''] +export type ValueOfAnObservable> = T['']; export interface Subscription { unsubscribe(): void; From ce3c41a0a87c6d9b8e3a2dc74ad2c3f6c83a4677 Mon Sep 17 00:00:00 2001 From: "Piotr \"Hitori\" Bosak" Date: Wed, 2 Aug 2017 13:32:55 +0200 Subject: [PATCH 3/4] Added version header --- types/kefir/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/kefir/index.d.ts b/types/kefir/index.d.ts index ea823f73ff..86885f1776 100644 --- a/types/kefir/index.d.ts +++ b/types/kefir/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Aya Morisawa // Piotr Hitori Bosak // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 /// @@ -31,7 +32,7 @@ export interface Observer { } export interface Observable { - '': T // TypeScript hack to enable value unwrapping for combine/flatMap + '': T; // TypeScript hack to enable value unwrapping for combine/flatMap toProperty(getCurrent?: () => T): Property; // Subscribe / add side effects From 0402f45814e9b6230e47fe69e02e8ce5fc076cdf Mon Sep 17 00:00:00 2001 From: "Piotr \"Hitori\" Bosak" Date: Mon, 7 Aug 2017 13:28:14 +0200 Subject: [PATCH 4/4] kefir.js: onValue/onError/onAny allows chaining --- types/kefir/index.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/types/kefir/index.d.ts b/types/kefir/index.d.ts index 86885f1776..e892e1b291 100644 --- a/types/kefir/index.d.ts +++ b/types/kefir/index.d.ts @@ -36,14 +36,14 @@ export interface Observable { toProperty(getCurrent?: () => T): Property; // 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) => void): void; - offAny(callback: (event: Event) => void): 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) => void): this; + offAny(callback: (event: Event) => void): this; log(name?: string): this; spy(name?: string): this; offLog(name?: string): this; @@ -178,8 +178,8 @@ export interface Property extends Observable { } export interface ObservablePool extends Observable { - plug(obs: Observable): void; - unPlug(obs: Observable): void; + plug(obs: Observable): this; + unPlug(obs: Observable): this; } export interface Event {