// Type definitions for Kefir 3.2.0 // Project: http://rpominov.github.io/kefir/ // Definitions by: Aya Morisawa // Definitions: https://github.com/borisyankov/DefinitelyTyped /// declare module "kefir" { export interface Observable { // 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; log(name?: string): void; offLog(name?: string): void; flatten(transformer?: (value: T) => U[]): Stream; toPromise(PromiseConstructor?: any): any; toESObservable(): any; } export interface Stream extends Observable { toProperty(getCurrent?: () => T): Property; // Modify an stream map(fn: (value: T) => U): Stream; filter(predicate?: (value: T) => boolean): Stream; take(n: number): Stream; takeWhile(predicate?: (value: T) => boolean): Stream; last(): Stream; skip(n: number): Stream; 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; delay(wait: number): Stream; throttle(wait: number, options?: {leading?: boolean, trailing?: boolean}): Stream; debounce(wait: number, options?: {immediate: boolean}): Stream; valuesToErrors(handler?: (value: T) => {convert: boolean, error: U}): Stream; errorsToValues(handler?: (error: S) => {convert: boolean, value: U}): Stream; mapErrors(fn: (error: S) => U): Stream; filterErrors(predicate?: (error: S) => boolean): Stream; endOnError(): Stream; takeErrors(n: number): Stream; ignoreValues(): Stream; ignoreErrors(): Stream; ignoreEnd(): Stream; beforeEnd(fn: () => U): Stream; slidingWindow(max: number, mix?: number): Stream; bufferWhile(predicate: (value: T) => boolean): Stream; bufferWithCount(count: number, options?: {flushOnEnd: boolean}): Stream; 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; flatMapLatest(fn: (value: T) => Stream): Stream; flatMapFirst(fn: (value: T) => Stream): Stream; flatMapConcat(fn: (value: T) => Stream): Stream; 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; skipUntilBy(otherObs: Observable): Stream; takeUntilBy(otherObs: Observable): Stream; bufferBy(otherObs: Observable, options?: {flushOnEnd: boolean}): Stream; bufferWhileBy(otherObs: Observable, options?: {flushOnEnd?: boolean, flushOnChange?: boolean}): Stream; awaiting(otherObs: Observable): Stream; } export interface Property extends Observable { changes(): Stream; // Modify an property map(fn: (value: T) => U): Property; filter(predicate?: (value: T) => boolean): Property; take(n: number): Property; takeWhile(predicate?: (value: T) => boolean): Property; last(): Property; skip(n: number): Property; skipWhile(predicate?: (value: T) => boolean): Property; skipDuplicates(comparator?: (a: T, b: T) => boolean): Property; diff(fn?: (prev: T, next: T) => T, seed?: T): Property; scan(fn: (prev: T, next: T) => T, seed?: T): Property; delay(wait: number): Property; throttle(wait: number, options?: {leading?: boolean, trailing?: boolean}): Property; debounce(wait: number, options?: {immediate: boolean}): Property; valuesToErrors(handler?: (value: T) => {convert: boolean, error: U}): Property; errorsToValues(handler?: (error: S) => {convert: boolean, value: U}): Property; mapErrors(fn: (error: S) => U): Property; filterErrors(predicate?: (error: S) => boolean): Property; endOnError(): Property; takeErrors(n: number): Stream; ignoreValues(): Property; ignoreErrors(): Property; ignoreEnd(): Property; beforeEnd(fn: () => U): Property; slidingWindow(max: number, mix?: number): Property; bufferWhile(predicate: (value: T) => boolean): Property; bufferWithCount(count: number, options?: {flushOnEnd: boolean}): Property; 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; flatMapLatest(fn: (value: T) => Property): Property; flatMapFirst(fn: (value: T) => Property): Property; 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; skipUntilBy(otherObs: Observable): Property; takeUntilBy(otherObs: Observable): Property; bufferBy(otherObs: Observable, options?: {flushOnEnd: boolean}): Property; bufferWhileBy(otherObs: Observable, options?: {flushOnEnd?: boolean, flushOnChange?: boolean}): Property; awaiting(otherObs: Observable): Property; } export interface ObservablePool extends Observable { plug(obs: Observable): void; unPlug(obs: Observable): void; } export interface Event { type: string; value: T; } export interface Emitter { emit(value: T): void; error(error: S): void; end(): void; emitEvent(event: {type: string, value: T | S}): void; } // Create a stream export function never(): Stream; export function later(wait: number, value: T): Stream; export function interval(interval: number, value: T): Stream; export function sequentially(interval: number, values: T[]): Stream; export function fromPoll(interval: number, fn: () => T): Stream; export function withInterval(interval: number, handler: (emitter: Emitter) => void): Stream; export function fromCallback(fn: (callback: (value: T) => void) => void): Stream; export function fromNodeCallback(fn: (callback: (error: S, result: T) => void) => void): Stream; export function fromEvents(target: EventTarget | NodeJS.EventEmitter | { on: Function, off: Function }, eventName: string, transform?: (value: T) => S): Stream; export function stream(subscribe: (emitter: Emitter) => Function | void): Stream; export function fromESObservable(observable: any): Stream // Create a property export function constant(value: T): Property; export function constantError(error: T): Property; export function fromPromise(promise: any): Property; // Combine observables export function combine(obss: Observable[], passiveObss: Observable[], combinator?: (...values: T[]) => U): Observable; export function combine(obss: Observable[], combinator?: (...values: T[]) => U): Observable; export function zip(obss: Observable[], passiveObss?: Observable[], combinator?: (...values: T[]) => U): Observable; export function merge(obss: Observable[]): Observable; export function concat(obss: Observable[]): Observable; export function pool(): ObservablePool; export function repeat(generator: (i: number) => Observable | boolean): Observable; }