Skip to content

Commit 2bbbbf6

Browse files
style(typings): Added typings for extended operators
1 parent f83e37b commit 2bbbbf6

File tree

4 files changed

+66
-23
lines changed

4 files changed

+66
-23
lines changed

src/KitchenSinkOperators.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as operators from './operator-typings';
2+
import {CoreOperators} from './CoreOperators';
3+
export interface KitchenSinkOperators<T> extends CoreOperators<T> {
4+
isEmpty: operators.operator_proto_isEmpty<T>;
5+
elementAt: operators.operator_proto_elementAt<T>;
6+
distinctUntilKeyChanged: operators.operator_proto_distinctUntilKeyChanged<T>;
7+
find: operators.operator_proto_find<T>;
8+
findIndex: operators.operator_proto_findIndex<T>;
9+
max: operators.operator_proto_max<T>;
10+
min: operators.operator_proto_min<T>;
11+
timeInterval: operators.operator_proto_timeInterval<T>;
12+
mergeScan: operators.operator_proto_mergeScan<T>;
13+
switchFirst: operators.operator_proto_switchFirst<T>;
14+
switchMapFirst: operators.operator_proto_switchMapFirst<T>;
15+
}

src/Rx.KitchenSink.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
import {Observable} from './Observable';
22
import {CoreOperators} from './CoreOperators';
3+
import {KitchenSinkOperators} from './KitchenSinkOperators';
34
import {Scheduler as IScheduler} from './Scheduler';
45
import {_PredicateObservable} from './types';
5-
6-
interface KitchenSinkOperators<T> extends CoreOperators<T> {
7-
isEmpty?: () => Observable<boolean>;
8-
elementAt?: (index: number, defaultValue?: any) => Observable<T>;
9-
distinctUntilKeyChanged?: (key: string, compare?: (x: any, y: any) => boolean, thisArg?: any) => Observable<T>;
10-
find?: (predicate: _PredicateObservable<T>, thisArg?: any) => Observable<T>;
11-
findIndex?: (predicate: _PredicateObservable<T>, thisArg?: any) => Observable<number>;
12-
max?: <T, R>(comparer?: (x: R, y: T) => R) => Observable<R>;
13-
min?: <T, R>(comparer?: (x: R, y: T) => R) => Observable<R>;
14-
timeInterval?: <T>(scheduler?: IScheduler) => Observable<T>;
15-
mergeScan?: <T, R>(project: (acc: R, x: T) => Observable<R>, seed: R) => Observable<R>;
16-
switchFirst?: () => Observable<T>;
17-
switchMapFirst?: <R>(project: ((x: T, ix: number) => Observable<any>),
18-
projectResult?: (x: T, y: any, ix: number, iy: number) => R) => Observable<R>;
19-
}
6+
import * as operators from './operator-typings';
207

218
// operators
229
/* tslint:disable:no-use-before-declare */
@@ -75,7 +62,7 @@ import {zip as zipStatic} from './operators/zip-static';
7562
Observable.zip = zipStatic;
7663

7764
// Operators
78-
const observableProto = (<KitchenSinkOperators<any>>Observable.prototype);
65+
const observableProto:KitchenSinkOperators<any> = (<any>Observable.prototype);
7966

8067
import {buffer} from './operators/buffer';
8168
observableProto.buffer = buffer;
@@ -278,10 +265,10 @@ import {switchMapTo} from './operators/switchMapTo';
278265
observableProto.switchMapTo = switchMapTo;
279266

280267
import {switchFirst} from './operators/switchFirst';
281-
observableProto.switchFirst = switchFirst;
268+
observableProto.switchFirst = <any>switchFirst;
282269

283270
import {switchMapFirst} from './operators/switchMapFirst';
284-
observableProto.switchMapFirst = switchMapFirst;
271+
observableProto.switchMapFirst = <any>switchMapFirst;
285272

286273
import {take} from './operators/take';
287274
observableProto.take = take;

src/operator-typings.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Subject} from './Subject';
66
import {Observer} from './Observer';
77
import {GroupedObservable} from './operators/groupBy-support';
88
import {GroupByObservable} from './operators/groupBy';
9+
import {TimeInterval} from './operators/extended/timeInterval';
910
import {_Selector, _IndexSelector, _SwitchMapResultSelector, _MergeMapProjector, _Predicate, _PredicateObservable, _Comparer, _Accumulator, _MergeAccumulator} from './types';
1011

1112
export interface operator_proto_buffer<T> {
@@ -269,3 +270,37 @@ export interface operator_proto_zip<T> {
269270
export interface operator_proto_zipAll<T> {
270271
<R>(project?: (...values: Array<any>) => R): Observable<R>;
271272
}
273+
export interface operator_proto_isEmpty<T> {
274+
(): Observable<T>;
275+
}
276+
export interface operator_proto_elementAt<T> {
277+
(index: number, defaultValue?: T): Observable<T>;
278+
}
279+
export interface operator_proto_distinctUntilKeyChanged<T> {
280+
(key: string, compare?: _Comparer<T, boolean>, thisArg?: any): Observable<T>;
281+
}
282+
export interface operator_proto_find<T> {
283+
(predicate: _PredicateObservable<T>, thisArg?: any): Observable<T>;
284+
}
285+
export interface operator_proto_findIndex<T> {
286+
(predicate: _PredicateObservable<T>, thisArg?: any): Observable<number>;
287+
}
288+
export interface operator_proto_max<T> {
289+
<R>(comparer?: _Comparer<T, R>): Observable<R>;
290+
}
291+
export interface operator_proto_min<T> {
292+
<R>(comparer?: _Comparer<T, R>): Observable<R>;
293+
}
294+
export interface operator_proto_timeInterval<T> {
295+
(scheduler?: Scheduler): Observable<TimeInterval>;
296+
}
297+
export interface operator_proto_mergeScan<T> {
298+
<R>(project: _MergeAccumulator<T, R>, seed: R): Observable<R>;
299+
}
300+
export interface operator_proto_switchFirst<T> {
301+
(): Observable<T>;
302+
}
303+
export interface operator_proto_switchMapFirst<T> {
304+
<R>(project: _MergeMapProjector<T, R>): Observable<R>;
305+
<R, R2>(project: _MergeMapProjector<T, R>, resultSelector?: _SwitchMapResultSelector<T, R, R2>): Observable<R2>;
306+
}

typingsgen.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
var fs = require('fs');
2-
var regex = /export interface CoreOperators<T> \{([\S|\s]*)\}/;
2+
var regex = /export interface .*?Operators<T> \{([\S|\s]*)\}/;
33

44
var content = fs.readFileSync('./src/CoreOperators.ts').toString();
5-
var contentResult = content.match(regex)[1].trim();
5+
var content2 = fs.readFileSync('./src/KitchenSinkOperators.ts').toString();
6+
var contentResult = content.match(regex)[1].trim() + '\n' + content2.match(regex)[1].trim();
67
var contents = contentResult.split('\n');
78
var extraSpaceRegex = / /;
89

@@ -15,6 +16,7 @@ import {Subject} from \'./Subject\';\n\
1516
import {Observer} from \'./Observer\';\n\
1617
import {GroupedObservable} from \'./operators/groupBy-support\';\n\
1718
import {GroupByObservable} from \'./operators/groupBy\';\n\
19+
import {TimeInterval} from \'./operators/extended/timeInterval\';\n\
1820
import {_Selector, _IndexSelector, _SwitchMapResultSelector, _MergeMapProjector, _Predicate, _PredicateObservable, _Comparer, _Accumulator, _MergeAccumulator} from \'./types\';\n\n\
1921
';
2022

@@ -28,9 +30,13 @@ for (var i = 0; i < contents.length; i++) {
2830
}
2931

3032
var property = file[1].trim();
31-
var filename = file[2];
32-
var fileContent = fs.readFileSync('./src/operators/'+filename+'.ts').toString();
33-
33+
var filename = file[2].trim();
34+
if (fs.existsSync('./src/operators/'+filename+'.ts')) {
35+
var fileContent = fs.readFileSync('./src/operators/'+filename+'.ts').toString();
36+
} else {
37+
var fileContent = fs.readFileSync('./src/operators/extended/'+filename+'.ts').toString();
38+
}
39+
3440
var methods = [];
3541

3642
var r = new RegExp('export function [_]?'+ filename +'([\\s|\\S]*?[\\;\\{])', 'g');

0 commit comments

Comments
 (0)