Skip to content

Commit

Permalink
fix(src): update to TypeScript 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Dec 12, 2016
1 parent f3ff581 commit b3a0cf6
Show file tree
Hide file tree
Showing 46 changed files with 235 additions and 250 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
"most": "^1.0.3",
"sinon": "^1.16.0",
"strip-comments": "^0.4.4",
"ts-node": "^0.9.0",
"tsify": "^2.0.3",
"tslint": "^3.6.0",
"typescript": "^2.0.3",
"typings": "^1.4.0",
"ts-node": "1.7.2",
"tsify": "2.0.3",
"tslint": "4.0.2",
"typescript": "2.1.4",
"typings": "2.0.0",
"uglify-js": "^2.6.2",
"validate-commit-msg": "^2.4.0"
},
Expand Down
60 changes: 26 additions & 34 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Promise} from 'es6-promise';
import $$observable from 'symbol-observable';

const NO = {};
Expand Down Expand Up @@ -57,28 +56,21 @@ export interface Listener<T> {
complete: () => void;
}

export interface PartialListener<T> {
next?: (x: T) => void;
error?: (err: any) => void;
complete?: () => void;
}

export type Observable<T> = {
subscribe(listener: Listener<T>): { unsubscribe: () => void; }
}
};

export type FromInput<T> = Promise<T> | Stream<T> | Array<T> | Observable<T>;

// mutates the input
function internalizeProducer<T>(producer: Producer<T>) {
(producer as InternalProducer<T> & Producer<T>)._start =
function _start(il: InternalListener<T>) {
(il as InternalListener<T> & Listener<T>).next = il._n;
(il as InternalListener<T> & Listener<T>).error = il._e;
(il as InternalListener<T> & Listener<T>).complete = il._c;
this.start(il as InternalListener<T> & Listener<T>);
};
(producer as InternalProducer<T> & Producer<T>)._stop = producer.stop;
function internalizeProducer<T>(producer: Producer<T> & Partial<InternalProducer<T>>) {
producer._start = function _start(il: InternalListener<T> & Partial<Listener<T>>) {
il.next = il._n;
il.error = il._e;
il.complete = il._c;
this.start(il);
};
producer._stop = producer.stop;
}

function and<T>(f1: (t: T) => boolean, f2: (t: T) => boolean): (t: T) => boolean {
Expand Down Expand Up @@ -604,7 +596,7 @@ class OtherIL<T> implements InternalListener<any> {
this.op = op;
}

_n(t: T) {
_n() {
this.op.end();
}

Expand Down Expand Up @@ -1339,20 +1331,20 @@ export class Stream<T> implements InternalListener<T> {
*
* @param {Listener<T>} listener
*/
addListener(listener: PartialListener<T>): void {
(listener as InternalListener<T> & Listener<T>)._n = listener.next || noop;
(listener as InternalListener<T> & Listener<T>)._e = listener.error || noop;
(listener as InternalListener<T> & Listener<T>)._c = listener.complete || noop;
this._add(listener as InternalListener<T> & Listener<T>);
addListener(listener: Partial<Listener<T> & InternalListener<T>>): void {
listener._n = listener.next || noop;
listener._e = listener.error || noop;
listener._c = listener.complete || noop;
this._add(listener as InternalListener<T>);
}

/**
* Removes a Listener from the Stream, assuming the Listener was added to it.
*
* @param {Listener<T>} listener
*/
removeListener(listener: Listener<T>): void {
this._remove(listener as InternalListener<T> & Listener<T>);
removeListener(listener: Partial<Listener<T> & InternalListener<T>>): void {
this._remove(listener as InternalListener<T>);
}

/**
Expand Down Expand Up @@ -1385,15 +1377,15 @@ export class Stream<T> implements InternalListener<T> {
* start, generate events, and stop the Stream.
* @return {Stream}
*/
static create<T>(producer?: Producer<T>): Stream<T> {
static create<T>(producer?: Producer<T> & Partial<InternalProducer<T>>): Stream<T> {
if (producer) {
if (typeof producer.start !== 'function'
|| typeof producer.stop !== 'function') {
throw new Error('producer requires both start and stop functions');
}
internalizeProducer(producer); // mutates the input
}
return new Stream(producer as InternalProducer<T> & Producer<T>);
return new Stream(producer as InternalProducer<T>);
}

/**
Expand All @@ -1404,11 +1396,11 @@ export class Stream<T> implements InternalListener<T> {
* start, generate events, and stop the Stream.
* @return {MemoryStream}
*/
static createWithMemory<T>(producer?: Producer<T>): MemoryStream<T> {
static createWithMemory<T>(producer?: Producer<T> & Partial<InternalProducer<T>>): MemoryStream<T> {
if (producer) {
internalizeProducer(producer); // mutates the input
}
return new MemoryStream<T>(producer as InternalProducer<T> & Producer<T>);
return new MemoryStream<T>(producer as InternalProducer<T>);
}

/**
Expand Down Expand Up @@ -2129,16 +2121,16 @@ export class Stream<T> implements InternalListener<T> {
*
* @param {Listener<T>} listener
*/
setDebugListener(listener: Listener<T>) {
setDebugListener(listener: Partial<Listener<T> & InternalListener<T>> | null | undefined) {
if (!listener) {
this._d = false;
this._dl = NO as InternalListener<T>;
} else {
this._d = true;
(listener as InternalListener<T> & Listener<T>)._n = listener.next;
(listener as InternalListener<T> & Listener<T>)._e = listener.error;
(listener as InternalListener<T> & Listener<T>)._c = listener.complete;
this._dl = listener as InternalListener<T> & Listener<T>;
listener._n = listener.next || noop;
listener._e = listener.error || noop;
listener._c = listener.complete || noop;
this._dl = listener as InternalListener<T>;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/extra/dropRepeats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class DropRepeatsOperator<T> implements Operator<T, T> {
* checks if it is equal to previous event, by returning a boolean.
* @return {Stream}
*/
export default function dropRepeats<T>(isEqual: (<T>(x: T, y: T) => boolean) | undefined = void 0): <T>(ins: Stream<T>) => Stream<T> {
export default function dropRepeats(isEqual: (<T>(x: T, y: T) => boolean) | undefined = void 0): <T>(ins: Stream<T>) => Stream<T> {
return function dropRepeatsOperator<T>(ins: Stream<T>): Stream<T> {
return new Stream<T>(new DropRepeatsOperator<T>(ins, isEqual));
};
Expand Down
2 changes: 1 addition & 1 deletion src/extra/tween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type Easings = {
easeIn: Ease;
easeOut: Ease;
easeInOut: Ease;
}
};

export type NumericFunction = (input: number) => number;

Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Stream,
MemoryStream,
Listener,
PartialListener,
Producer,
Operator,
Observable,
Expand All @@ -11,7 +10,6 @@ export {
Stream,
MemoryStream,
Listener,
PartialListener,
Producer,
Operator,
Observable,
Expand Down
6 changes: 3 additions & 3 deletions tests/extra/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import concat from '../../src/extra/concat';
import * as assert from 'assert';

describe('concat (extra)', () => {
it('should concatenate two synchronous short streams together', (done) => {
it('should concatenate two synchronous short streams together', (done: any) => {
const stream1 = xs.of(1, 2, 3);
const stream2 = xs.of(40, 50, 60, 70);
const stream3 = xs.of(8, 9);
Expand All @@ -24,7 +24,7 @@ describe('concat (extra)', () => {
});
});

it('should concatenate two asynchronous short streams together', (done) => {
it('should concatenate two asynchronous short streams together', (done: any) => {
const stream1 = xs.periodic(50).take(3);
const stream2 = xs.periodic(100).take(2);
const stream = concat(stream1, stream2);
Expand All @@ -42,7 +42,7 @@ describe('concat (extra)', () => {
});
});

it('should append a synchronous stream after an asynchronous stream', (done) => {
it('should append a synchronous stream after an asynchronous stream', (done: any) => {
const stream1 = xs.periodic(50).take(3);
const stream2 = xs.of(30, 40, 50, 60);
const stream = concat(stream1, stream2);
Expand Down
2 changes: 1 addition & 1 deletion tests/extra/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import debounce from '../../src/extra/debounce';
import * as assert from 'assert';

describe('debounce (extra)', () => {
it('should delay events until a period of silence has passed', (done) => {
it('should delay events until a period of silence has passed', (done: any) => {
const producer: Producer<number> = {
start(out: Listener<number>) {
out.next(1);
Expand Down
4 changes: 2 additions & 2 deletions tests/extra/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import delay from '../../src/extra/delay';
import * as assert from 'assert';

describe('delay (extra)', () => {
it('should delay periodic events by a given time period', (done) => {
it('should delay periodic events by a given time period', (done: any) => {
const stream = xs.periodic(100).take(3).compose(delay(200));
const expected = [0, 1, 2];
let completeCalled = false;
Expand All @@ -28,7 +28,7 @@ describe('delay (extra)', () => {
}, 550);
});

it('should delay synchronous events by a given time period', (done) => {
it('should delay synchronous events by a given time period', (done: any) => {
const stream = xs.of(10, 20, 30).compose(delay(100));
const expected = [10, 20, 30];
let completeCalled = false;
Expand Down
10 changes: 5 additions & 5 deletions tests/extra/dropRepeats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dropRepeats from '../../src/extra/dropRepeats';
import * as assert from 'assert';

describe('dropRepeats (extra)', () => {
it('should drop consecutive duplicate numbers (as events)', (done) => {
it('should drop consecutive duplicate numbers (as events)', (done: any) => {
const stream = xs.of(1, 2, 1, 1, 1, 2, 3, 4, 3, 3).compose(dropRepeats());
const expected = [1, 2, 1, 2, 3, 4, 3];

Expand All @@ -22,7 +22,7 @@ describe('dropRepeats (extra)', () => {
});
});

it('should drop consecutive \'duplicate\' strings, with a custom isEqual', (done) => {
it('should drop consecutive \'duplicate\' strings, with a custom isEqual', (done: any) => {
const stream = xs.of('a', 'b', 'a', 'A', 'B', 'b')
.compose(dropRepeats((x: string, y: string) => x.toLowerCase() === y.toLowerCase()));
const expected = ['a', 'b', 'a', 'B'];
Expand All @@ -39,9 +39,9 @@ describe('dropRepeats (extra)', () => {
});
});

it('should drop consecutive duplicate numbers, with a circular stream dependency', (done) => {
it('should drop consecutive duplicate numbers, with a circular stream dependency', (done: any) => {
const streamProxy = xs.create();
const input = xs.of(0, 0, 1, 1, 1)
const input = xs.of(0, 0, 1, 1, 1);
const stream = xs.merge(streamProxy, input).compose(dropRepeats());
streamProxy.imitate(stream);
const expected = [0, 1];
Expand All @@ -64,7 +64,7 @@ describe('dropRepeats (extra)', () => {
});
});

it('should support dropping duplicates of combine arrays', (done) => {
it('should support dropping duplicates of combine arrays', (done: any) => {
const A: Stream<string> = fromDiagram('---a---b------b------|');
const B: Stream<string> = fromDiagram('-x---y---y------z--y-|');
const stream = xs.combine(A, B).compose(
Expand Down
4 changes: 2 additions & 2 deletions tests/extra/dropUntil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import delay from '../../src/extra/delay';
import * as assert from 'assert';

describe('dropUntil (extra)', () => {
it('should start emitting the stream when another stream emits next', (done) => {
it('should start emitting the stream when another stream emits next', (done: any) => {
const source = xs.periodic(50).take(6);
const other = xs.periodic(220).take(1);
const stream = source.compose(dropUntil(other));
Expand All @@ -24,7 +24,7 @@ describe('dropUntil (extra)', () => {
});
});

it('should complete the stream when another stream emits complete', (done) => {
it('should complete the stream when another stream emits complete', (done: any) => {
const source = xs.periodic(50).take(6);
const other = xs.empty().compose(delay(220));
const stream = source.compose(dropUntil(other));
Expand Down
14 changes: 7 additions & 7 deletions tests/extra/flattenConcurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as assert from 'assert';

describe('flattenConcurrently (extra)', () => {
describe('with map', () => {
it('should expand each periodic event with 3 sync events', (done) => {
it('should expand each periodic event with 3 sync events', (done: any) => {
const stream = xs.periodic(100).take(3)
.map(i => xs.of(1 + i, 2 + i, 3 + i))
.compose(flattenConcurrently);
Expand All @@ -24,7 +24,7 @@ describe('flattenConcurrently (extra)', () => {
});
});

it('should return a flat stream with correct TypeScript types', (done) => {
it('should return a flat stream with correct TypeScript types', (done: any) => {
const streamStrings: Stream<string> = Stream.create({
start: (listener: Listener<string>) => {},
stop: () => {}
Expand All @@ -41,7 +41,7 @@ describe('flattenConcurrently (extra)', () => {
done();
});

it('should expand 3 sync events as a periodic each', (done) => {
it('should expand 3 sync events as a periodic each', (done: any) => {
const stream = xs.of(0, 1, 2)
.map(i => xs.periodic(100 * (i + 1) + 10 * i).take(2).map(x => `${i}${x}`))
.compose(flattenConcurrently);
Expand All @@ -63,7 +63,7 @@ describe('flattenConcurrently (extra)', () => {
});
});

it('should expand 3 async events as a periodic each', (done) => {
it('should expand 3 async events as a periodic each', (done: any) => {
const stream = xs.periodic(140).take(3)
.map(i =>
xs.periodic(100 * (i < 2 ? 1 : i)).take(3).map(x => `${i}${x}`)
Expand All @@ -87,7 +87,7 @@ describe('flattenConcurrently (extra)', () => {
});
});

it('should expand 3 async events as a periodic each, no optimization', (done) => {
it('should expand 3 async events as a periodic each, no optimization', (done: any) => {
const stream = xs.periodic(140).take(3)
.map(i =>
xs.periodic(100 * (i < 2 ? 1 : i)).take(3).map(x => `${i}${x}`)
Expand All @@ -113,7 +113,7 @@ describe('flattenConcurrently (extra)', () => {
});
});

it('should propagate user mistakes in project as errors', (done) => {
it('should propagate user mistakes in project as errors', (done: any) => {
const source = xs.periodic(30).take(1);
const stream = source.map(
x => {
Expand All @@ -136,7 +136,7 @@ describe('flattenConcurrently (extra)', () => {
});

describe('with filter+map fusion', () => {
it('should execute the predicate, the projection, and the flattening', (done) => {
it('should execute the predicate, the projection, and the flattening', (done: any) => {
let predicateCallCount = 0;
let projectCallCount = 0;

Expand Down
Loading

0 comments on commit b3a0cf6

Please sign in to comment.