diff --git a/kefir/kefir-tests.ts b/kefir/kefir-tests.ts index a0d0a96186..94300550b4 100644 --- a/kefir/kefir-tests.ts +++ b/kefir/kefir-tests.ts @@ -30,7 +30,7 @@ import { Observable, ObservablePool, Stream, Property, Event, Emitter } from 'ke let stream10: Stream = Kefir.stream(emitter => { let count = 0; emitter.emit(count); - + let intervalId = setInterval(() => { count++; if (count < 4) { @@ -39,7 +39,7 @@ import { Observable, ObservablePool, Stream, Property, Event, Emitter } from 'ke emitter.end(); } }, 1000); - + return () => clearInterval(intervalId); }); } @@ -77,6 +77,7 @@ import { Observable, ObservablePool, Stream, Property, Event, Emitter } from 'ke let observable01: Stream = Kefir.sequentially(100, [1, 2, 3]).map(x => x + 1); let observable02: Stream = Kefir.sequentially(100, [1, 2, 3]).filter(x => x > 1); let observable03: Stream = Kefir.sequentially(100, [1, 2, 3]).take(2); + let observable29: Stream = Kefir.sequentially(100, [1, 2, 3]).takeErrors(2); let observable04: Stream = Kefir.sequentially(100, [1, 2, 3]).takeWhile(x => x < 3); let observable05: Stream = Kefir.sequentially(100, [1, 2, 3]).last(); let observable06: Stream = Kefir.sequentially(100, [1, 2, 3]).skip(2); @@ -103,14 +104,16 @@ import { Observable, ObservablePool, Stream, Property, Event, Emitter } from 'ke }).endOnError(); let observable22: Stream = Kefir.sequentially(100, [0, -1, 2, -3]).valuesToErrors(x => { return {convert: x < 0, error: x}; - }).skipValues(); + }).ignoreValues(); let observable23: Stream = Kefir.sequentially(100, [0, -1, 2, -3]).valuesToErrors(x => { return {convert: x < 0, error: x}; - }).skipErrors(); - let observable24: Stream = Kefir.sequentially(100, [1, 2, 3]).skipEnd(); + }).ignoreErrors(); + let observable24: Stream = Kefir.sequentially(100, [1, 2, 3]).ignoreEnd(); let ovservable25: Stream = Kefir.sequentially(100, [1, 2, 3]).beforeEnd(() => 0); let observable26: Stream = Kefir.sequentially(100, [1, 2, 3, 4, 5]).slidingWindow(3, 2) let observable27: Stream = Kefir.sequentially(100, [1, 2, 3, 4, 5]).bufferWhile(x => x !== 3); + let observable30: Stream = Kefir.sequentially(100, [1, 2, 3, 4, 5]).bufferWithCount(2); + let observable31: Stream = Kefir.sequentially(100, [1, 2, 3, 4, 5]).bufferWithTimeOrCount(330, 10); { var myTransducer: any; let observable28: Stream = Kefir.sequentially(100, [1, 2, 3, 4, 5, 6]).transduce(myTransducer); diff --git a/kefir/kefir.d.ts b/kefir/kefir.d.ts index 9e3303f01e..a95b12a887 100644 --- a/kefir/kefir.d.ts +++ b/kefir/kefir.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Kefir 2.8.1 +// Type definitions for Kefir 3.2.0 // Project: http://rpominov.github.io/kefir/ // Definitions by: Aya Morisawa // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -6,7 +6,7 @@ /// declare module "kefir" { - + export interface Observable { // Subscribe / add side effects onValue(callback: (value: T) => void): void; @@ -19,12 +19,14 @@ declare module "kefir" { 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; @@ -36,24 +38,26 @@ declare module "kefir" { 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; - flatten(transformer?: (value: T) => U[]): Stream; delay(wait: number): Stream; - throttle(wait: number, options?: {leading: boolean, trailing: boolean}): 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; - skipValues(): Stream; - skipErrors(): Stream; - skipEnd(): 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; @@ -65,20 +69,20 @@ declare module "kefir" { 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): 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; @@ -90,24 +94,26 @@ declare module "kefir" { 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; - flatten(transformer?: (value: T) => U[]): Property; delay(wait: number): Property; - throttle(wait: number, options?: {leading: boolean, trailing: boolean}): 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; - skipValues(): Property; - skipErrors(): Property; - skipEnd(): 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; @@ -119,35 +125,34 @@ declare module "kefir" { 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): 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; - current: boolean; } - + 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; @@ -159,12 +164,13 @@ declare module "kefir" { 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;