diff --git a/src/extra/buffer.ts b/src/extra/buffer.ts index 76074b0..1140ba4 100644 --- a/src/extra/buffer.ts +++ b/src/extra/buffer.ts @@ -4,7 +4,7 @@ class SeparatorIL implements InternalListener, OutSender> { constructor(public out: Stream>, private op: BufferOperator) { } - _n(t: any) { + _n(_t: any) { this.op.flush(); } @@ -21,7 +21,7 @@ class SeparatorIL implements InternalListener, OutSender> { class BufferOperator implements Operator> { public type = 'buffer'; public out: Stream> = null as any; - private sil: InternalListener; + private sil?: InternalListener; private acc: Array = []; constructor(public s: Stream, public ins: Stream) { @@ -45,7 +45,7 @@ class BufferOperator implements Operator> { this.flush(); this.ins._remove(this); this.out = null as any; - this.s._remove(this.sil); + this.s._remove(this.sil!); this.sil = NO_IL; } diff --git a/src/extra/dropUntil.ts b/src/extra/dropUntil.ts index 56b8451..a7bf4da 100644 --- a/src/extra/dropUntil.ts +++ b/src/extra/dropUntil.ts @@ -5,7 +5,7 @@ class OtherIL implements InternalListener, OutSender { private op: DropUntilOperator) { } - _n(t: T) { + _n(_t: T) { this.op.up(); } diff --git a/src/extra/fromEvent.ts b/src/extra/fromEvent.ts index c7839bc..d18b38f 100644 --- a/src/extra/fromEvent.ts +++ b/src/extra/fromEvent.ts @@ -1,10 +1,9 @@ -/// import {EventEmitter} from 'events'; import {Stream, InternalProducer, InternalListener} from '../index'; export class DOMEventProducer implements InternalProducer { public type = 'fromEvent'; - private listener: EventListener | null; + private listener?: EventListener | null; constructor(private node: EventTarget, private eventType: string, @@ -24,7 +23,7 @@ export class DOMEventProducer implements InternalProducer { export class NodeEventProducer implements InternalProducer { public type = 'fromEvent'; - private listener: Function | null; + private listener?: Function | null; constructor(private node: EventEmitter, private eventName: string) { } diff --git a/src/extra/split.ts b/src/extra/split.ts index faa8c01..834ace8 100644 --- a/src/extra/split.ts +++ b/src/extra/split.ts @@ -5,7 +5,7 @@ class SeparatorIL implements InternalListener, OutSender> { private op: SplitOperator) { } - _n(t: any) { + _n(_t: any) { this.op.up(); } diff --git a/src/index.ts b/src/index.ts index 83367e9..9910a41 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,7 +87,7 @@ function internalizeProducer(producer: Producer & Partial); }; producer._stop = producer.stop; } @@ -119,7 +119,7 @@ class Observer implements Listener { class FromObservable implements InternalProducer { public type = 'fromObservable'; public ins: Observable; - public out: Stream; + public out?: Stream; private active: boolean; private _sub: Subscription | undefined; @@ -1765,7 +1765,6 @@ export class Stream implements InternalListener { * @return {Stream} */ flatten(this: Stream>): T { - const p = this._prod; return new Stream(new Flatten(this)) as T & Stream; } @@ -1976,7 +1975,7 @@ export class Stream implements InternalListener { } export class MemoryStream extends Stream { - private _v: T; + private _v?: T; private _has: boolean = false; constructor(producer: InternalProducer) { super(producer); @@ -1994,14 +1993,14 @@ export class MemoryStream extends Stream { const a = this._ils; a.push(il); if (a.length > 1) { - if (this._has) il._n(this._v); + if (this._has) il._n(this._v!); return; } if (this._stopID !== NO) { - if (this._has) il._n(this._v); + if (this._has) il._n(this._v!); clearTimeout(this._stopID); this._stopID = NO; - } else if (this._has) il._n(this._v); else { + } else if (this._has) il._n(this._v!); else { const p = this._prod; if (p !== NO) p._start(this); } diff --git a/tests/extra/buffer.ts b/tests/extra/buffer.ts index ca3c70c..1aaa19f 100644 --- a/tests/extra/buffer.ts +++ b/tests/extra/buffer.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import buffer from '../../src/extra/buffer'; import delay from '../../src/extra/delay'; diff --git a/tests/extra/concat.ts b/tests/extra/concat.ts index b6ee23e..fb0ea46 100644 --- a/tests/extra/concat.ts +++ b/tests/extra/concat.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import concat from '../../src/extra/concat'; import * as assert from 'assert'; diff --git a/tests/extra/debounce.ts b/tests/extra/debounce.ts index 68dd9f0..74915f1 100644 --- a/tests/extra/debounce.ts +++ b/tests/extra/debounce.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Listener, Producer} from '../../src/index'; import debounce from '../../src/extra/debounce'; import fromDiagram from '../../src/extra/fromDiagram'; diff --git a/tests/extra/delay.ts b/tests/extra/delay.ts index 9df4b14..b6b5ccc 100644 --- a/tests/extra/delay.ts +++ b/tests/extra/delay.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import delay from '../../src/extra/delay'; import * as assert from 'assert'; diff --git a/tests/extra/dropRepeats.ts b/tests/extra/dropRepeats.ts index ae5bb8e..20d6b36 100644 --- a/tests/extra/dropRepeats.ts +++ b/tests/extra/dropRepeats.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream} from '../../src/index'; import fromDiagram from '../../src/extra/fromDiagram'; import dropRepeats from '../../src/extra/dropRepeats'; @@ -21,7 +19,7 @@ describe('dropRepeats (extra)', () => { }, }); }); - + it('should complete when input completes', (done: any) => { const stream = xs.of(1).compose(dropRepeats()); const expected = [1]; @@ -56,7 +54,7 @@ describe('dropRepeats (extra)', () => { }); it('should drop consecutive duplicate numbers, with a circular stream dependency', (done: any) => { - const streamProxy = xs.create(); + const streamProxy = xs.create(); const input = xs.of(0, 0, 1, 1, 1); const stream = xs.merge(streamProxy, input).compose(dropRepeats()); streamProxy.imitate(stream); @@ -71,7 +69,7 @@ describe('dropRepeats (extra)', () => { }); input.addListener({ - next: (x: number) => {}, + next: () => {}, error: (err: any) => done(err), complete: () => { assert.equal(expected.length, 0); @@ -82,7 +80,8 @@ describe('dropRepeats (extra)', () => { it('should return the correct TypeScript types', (done: any) => { const first: Stream = xs.never(); - const second: Stream = first.compose(dropRepeats((x, y) => false)); + const second: Stream = first.compose(dropRepeats((_x, _y) => false)); + second.drop(0); // no unused variable done(); }); diff --git a/tests/extra/dropUntil.ts b/tests/extra/dropUntil.ts index c0a75ad..5168326 100644 --- a/tests/extra/dropUntil.ts +++ b/tests/extra/dropUntil.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import concat from '../../src/extra/concat'; import dropUntil from '../../src/extra/dropUntil'; diff --git a/tests/extra/flattenConcurrently.ts b/tests/extra/flattenConcurrently.ts index fbb13ba..2cb5e4f 100644 --- a/tests/extra/flattenConcurrently.ts +++ b/tests/extra/flattenConcurrently.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, Listener} from '../../src/index'; import flattenConcurrently from '../../src/extra/flattenConcurrently'; import * as assert from 'assert'; @@ -26,18 +24,19 @@ describe('flattenConcurrently (extra)', () => { it('should return a flat stream with correct TypeScript types', (done: any) => { const streamStrings: Stream = Stream.create({ - start: (listener: Listener) => {}, + start: (_listener: Listener) => {}, stop: () => {} }); const streamBooleans: Stream = Stream.create({ - start: (listener: Listener) => {}, + start: (_listener: Listener) => {}, stop: () => {} }); // Type checked by the compiler. Without Stream it does not compile. - const flat: Stream = streamStrings.map(x => streamBooleans) + const flat: Stream = streamStrings.map(_x => streamBooleans) .compose(flattenConcurrently); + flat.drop(0); // no unused variable done(); }); diff --git a/tests/extra/flattenSequentially.ts b/tests/extra/flattenSequentially.ts index 1242378..3803910 100644 --- a/tests/extra/flattenSequentially.ts +++ b/tests/extra/flattenSequentially.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import flattenSequentially from '../../src/extra/flattenSequentially'; import * as assert from 'assert'; @@ -156,7 +154,7 @@ describe('flattenSequentially (extra)', () => { const expectedInner = [0, 1]; const stream = xs.of(1) - .map(i => + .map(_i => xs.periodic(150).take(3) // 150ms, 300ms, 450ms, 600ms .debug(x => assert.strictEqual(x, expectedInner.shift())) ) diff --git a/tests/extra/fromDiagram.ts b/tests/extra/fromDiagram.ts index 7a7e1d1..4ba8a03 100644 --- a/tests/extra/fromDiagram.ts +++ b/tests/extra/fromDiagram.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import fromDiagram from '../../src/extra/fromDiagram'; import * as assert from 'assert'; @@ -29,7 +27,7 @@ describe('fromDiagram (extra)', () => { next: (x: number) => { assert.equal(x, expected.shift()); }, - error: (err) => { + error: (_err) => { assert.equal(expected.length, 0); done(); }, diff --git a/tests/extra/fromEvent.ts b/tests/extra/fromEvent.ts index 8be3ced..f4b67af 100644 --- a/tests/extra/fromEvent.ts +++ b/tests/extra/fromEvent.ts @@ -1,5 +1,3 @@ -/// -/// import {EventEmitter} from 'events'; import fromEvent from '../../src/extra/fromEvent'; import * as assert from 'assert'; @@ -7,10 +5,10 @@ function noop() {} class FakeEventTarget implements EventTarget { public handler: EventListener | undefined; - public event: string; - public capture: boolean; - public removedEvent: string; - public removedCapture: boolean; + public event?: string; + public capture?: boolean; + public removedEvent?: string; + public removedCapture?: boolean; constructor() {} @@ -27,28 +25,28 @@ class FakeEventTarget implements EventTarget { this.capture = capture; } - removeEventListener(e: string, handler: EventListener, capture: boolean) { + removeEventListener(e: string, _handler: EventListener, capture: boolean) { this.removedEvent = e; this.removedCapture = capture; this.handler = void 0; } - dispatchEvent(event: Event) { + dispatchEvent(_event: Event) { return true; } } class FakeEventEmitter extends EventEmitter { public handler: Function | undefined; - public event: string | symbol; - public removedEvent: string | symbol; + public event?: string | symbol; + public removedEvent?: string | symbol; constructor() { super(); } - emit( eventName: string, ...args: any[] ): any { + emit(_eventName: string, ...args: any[] ): any { if (typeof this.handler !== 'function') { return; } @@ -62,7 +60,7 @@ class FakeEventEmitter extends EventEmitter { return this; } - removeListener(e: string, handler: Function): this { + removeListener(e: string, _handler: Function): this { this.removedEvent = e; this.handler = void 0; return this; @@ -118,7 +116,7 @@ describe('fromEvent (extra) - DOMEvent', () => { const stream = fromEvent(target, 'test', true); stream.take(1).addListener({ - next: (x) => {}, + next: () => {}, error: (err: any) => done(err), complete() { setTimeout(() => { @@ -172,7 +170,7 @@ describe('fromEvent (extra) - EventEmitter', () => { const stream = fromEvent(target, 'test'); stream.take(1).addListener({ - next: (x) => {}, + next: () => {}, error: (err: any) => done(err), complete() { setTimeout(() => { diff --git a/tests/extra/pairwise.ts b/tests/extra/pairwise.ts index 607e621..290745c 100644 --- a/tests/extra/pairwise.ts +++ b/tests/extra/pairwise.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import pairwise from '../../src/extra/pairwise'; import * as assert from 'assert'; diff --git a/tests/extra/sampleCombine.ts b/tests/extra/sampleCombine.ts index 1a66e48..6ea092a 100644 --- a/tests/extra/sampleCombine.ts +++ b/tests/extra/sampleCombine.ts @@ -1,5 +1,3 @@ -/// -/// import xs, { Stream } from '../../src/index'; import sampleCombine from '../../src/extra/sampleCombine'; import * as assert from 'assert'; @@ -30,17 +28,18 @@ describe('sampleCombine (extra)', () => { it('should have correct TypeScript signature', (done: any) => { const stream1 = xs.create({ - start: listener => { }, + start: _listener => { }, stop: () => { } }); const stream2 = xs.create({ - start: listener => { }, + start: _listener => { }, stop: () => { } }); const combined: Stream<[string, string]> = stream1 .compose(sampleCombine(stream2)); + combined.drop(0); // no unused variables done(); }); diff --git a/tests/extra/split.ts b/tests/extra/split.ts index 410acaf..f6b9cdf 100644 --- a/tests/extra/split.ts +++ b/tests/extra/split.ts @@ -1,5 +1,3 @@ -/// -/// import xs, { Stream } from '../../src/index'; import split from '../../src/extra/split'; import concat from '../../src/extra/concat'; diff --git a/tests/extra/throttle.ts b/tests/extra/throttle.ts index 1babc2d..a5b5b94 100644 --- a/tests/extra/throttle.ts +++ b/tests/extra/throttle.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Listener, Producer} from '../../src/index'; import throttle from '../../src/extra/throttle'; import * as assert from 'assert'; diff --git a/tests/extra/tween.ts b/tests/extra/tween.ts index d0cee81..7d0e925 100644 --- a/tests/extra/tween.ts +++ b/tests/extra/tween.ts @@ -1,6 +1,4 @@ -/// -/// -import xs, {Stream} from '../../src/index'; +import {Stream} from '../../src/index'; import tween from '../../src/extra/tween'; import * as assert from 'assert'; @@ -25,7 +23,7 @@ function setCharAt(str: string, idx: number, chr: string): string { function rotate(lines: Array): Array { let len = lines[0].length; return lines[0].split('') - .map((col, i) => + .map((_col, i) => lines.map(row => row.split('')[len - i - 1]) ) .map(row => row.join('')); @@ -44,7 +42,7 @@ function plot(position$: Stream): Stream { .last() .map(arr => { let coords = arr.map((y, x) => [x, y]); - let lines = coords.reduce((lines, [x, y]) => { + let lines = coords.reduce((lines, [_x, y]) => { let newline: string; if (y < 0) { newline = setCharAt(stutter(' ', STEPS + 1), 0, '_'); diff --git a/tests/factory/combine.ts b/tests/factory/combine.ts index 4f126c9..3212fd7 100644 --- a/tests/factory/combine.ts +++ b/tests/factory/combine.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream} from '../../src/index'; import * as assert from 'assert'; @@ -50,16 +48,17 @@ describe('xs.combine', () => { it('should have correct TypeScript signature', (done: any) => { const stream1 = xs.create({ - start: listener => {}, + start: _listener => {}, stop: () => {} }); const stream2 = xs.create({ - start: listener => {}, + start: _listener => {}, stop: () => {} }); const combined: Stream<[string, string]> = xs.combine(stream1, stream2); + combined.drop(0); // no unused variables done(); }); diff --git a/tests/factory/empty.ts b/tests/factory/empty.ts index 3b95919..50e0b69 100644 --- a/tests/factory/empty.ts +++ b/tests/factory/empty.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; describe('xs.empty()', function() { diff --git a/tests/factory/from.ts b/tests/factory/from.ts index 7ff135f..e94306b 100644 --- a/tests/factory/from.ts +++ b/tests/factory/from.ts @@ -1,5 +1,3 @@ -/// -/// import {Promise} from 'es6-promise'; import xs, { Observable } from '../../src/index'; import * as assert from 'assert'; @@ -27,7 +25,7 @@ describe('xs.from', () => { const stream = xs.from(Promise.reject('no')); stream.addListener({ - next: (x: string) => done('next should not be called'), + next: () => done('next should not be called'), error: (err: any) => { assert.strictEqual(err, 'no'); done(); diff --git a/tests/factory/fromArray.ts b/tests/factory/fromArray.ts index 73aa00c..1f7e776 100644 --- a/tests/factory/fromArray.ts +++ b/tests/factory/fromArray.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import * as assert from 'assert'; diff --git a/tests/factory/fromObservable.ts b/tests/factory/fromObservable.ts index 7ac1594..b66badb 100644 --- a/tests/factory/fromObservable.ts +++ b/tests/factory/fromObservable.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import * as assert from 'assert'; @@ -25,7 +23,7 @@ describe('xs.fromObservable', () => { }); it('should support synchronous unsubscribe on completion', (done: any) => { - const stream = xs.fromObservable(xs.of(10, 20, 30)); + const stream = xs.fromObservable(xs.of(10, 20, 30)); let expected = [10, 20, 30]; stream.addListener({ diff --git a/tests/factory/fromPromise.ts b/tests/factory/fromPromise.ts index aceb4d5..617ccbc 100644 --- a/tests/factory/fromPromise.ts +++ b/tests/factory/fromPromise.ts @@ -1,5 +1,3 @@ -/// -/// import {Promise} from 'es6-promise'; import xs from '../../src/index'; import * as assert from 'assert'; @@ -26,7 +24,7 @@ describe('xs.fromPromise', () => { const stream = xs.fromPromise(Promise.reject('no')); stream.addListener({ - next: (x: string) => done('next should not be called'), + next: () => done('next should not be called'), error: (err: any) => { assert.strictEqual(err, 'no'); done(); diff --git a/tests/factory/merge.ts b/tests/factory/merge.ts index 01758ae..36e4a75 100644 --- a/tests/factory/merge.ts +++ b/tests/factory/merge.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream} from '../../src/index'; import * as assert from 'assert'; @@ -77,22 +75,25 @@ describe('xs.merge', () => { it('should have a correct TypeScript signature', () => { const bools = xs.create({ - start: listener => {}, + start: _listener => {}, stop: () => {} }); const numbers = xs.create({ - start: listener => {}, + start: _listener => {}, stop: () => {} }); const strings = xs.create({ - start: listener => {}, + start: _listener => {}, stop: () => {} }); const emptyIsh: Stream = xs.merge(); const doubled: Stream = xs.merge(bools, strings); const tripled: Stream = xs.merge(bools, strings, numbers); + emptyIsh.drop(0); // no unused variable + doubled.drop(0); // no unused variable + tripled.drop(0); // no unused variable }); }); diff --git a/tests/factory/never.ts b/tests/factory/never.ts index 0bdad4c..b9ff0e6 100644 --- a/tests/factory/never.ts +++ b/tests/factory/never.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; describe('xs.never()', () => { diff --git a/tests/factory/of.ts b/tests/factory/of.ts index 63a1448..63d89e5 100644 --- a/tests/factory/of.ts +++ b/tests/factory/of.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import * as assert from 'assert'; diff --git a/tests/factory/throw.ts b/tests/factory/throw.ts index be92332..e390326 100644 --- a/tests/factory/throw.ts +++ b/tests/factory/throw.ts @@ -1,5 +1,3 @@ -/// -/// import xs from '../../src/index'; import * as assert from 'assert'; diff --git a/tests/memoryStream.ts b/tests/memoryStream.ts index 0bc7f2d..b27900c 100644 --- a/tests/memoryStream.ts +++ b/tests/memoryStream.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Listener} from '../src/index'; import * as assert from 'assert'; @@ -187,7 +185,7 @@ describe('MemoryStream', () => { next: (x) => { assert.strictEqual(x, expectedA.shift()); }, - error: (err) => {}, + error: (err) => done(err), complete: () => { completeCalled += 1; }, @@ -197,7 +195,7 @@ describe('MemoryStream', () => { next: (x) => { assert.strictEqual(x, expectedB.shift()); }, - error: (err) => {}, + error: (err) => done(err), complete: () => { completeCalled += 1; } @@ -237,7 +235,7 @@ describe('MemoryStream', () => { assert.strictEqual(x, expectedA.shift()); source$.removeListener(listenerA); }, - error: (err: any) => {}, + error: (err: any) => done(err), complete: () => { completeCalled += 1; }, @@ -249,7 +247,7 @@ describe('MemoryStream', () => { next: (x) => { assert.strictEqual(x, expectedB.shift()); }, - error: (err) => {}, + error: (err) => done(err), complete: () => { completeCalled += 1; } diff --git a/tests/operator/debug.ts b/tests/operator/debug.ts index 7726b41..e25a19c 100644 --- a/tests/operator/debug.ts +++ b/tests/operator/debug.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; import * as sinon from 'sinon'; diff --git a/tests/operator/drop.ts b/tests/operator/drop.ts index 97ff077..2c76f39 100644 --- a/tests/operator/drop.ts +++ b/tests/operator/drop.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; diff --git a/tests/operator/endWhen.ts b/tests/operator/endWhen.ts index 4706c13..fba94b6 100644 --- a/tests/operator/endWhen.ts +++ b/tests/operator/endWhen.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import delay from '../../src/extra/delay'; import * as assert from 'assert'; diff --git a/tests/operator/filter.ts b/tests/operator/filter.ts index 1d0970b..3df743c 100644 --- a/tests/operator/filter.ts +++ b/tests/operator/filter.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; @@ -127,10 +125,10 @@ describe('Stream.prototype.filter', () => { it('should return stream of constrained type if predicate is type guard', (done: any) => { class Animal { } class Dog extends Animal { - thisIsADog: boolean; + thisIsADog?: boolean; } class Cat extends Animal { - thisIsACat: boolean; + thisIsACat?: boolean; } function isDog(a: Animal): a is Dog { @@ -141,6 +139,7 @@ describe('Stream.prototype.filter', () => { new Animal(), new Cat(), new Dog(), new Animal() ); const output: Stream = input.filter(isDog); + output.drop(0); // no unused variable done(); }); }); diff --git a/tests/operator/flatten.ts b/tests/operator/flatten.ts index 152b4d0..3c386a1 100644 --- a/tests/operator/flatten.ts +++ b/tests/operator/flatten.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, Listener} from '../../src/index'; import fromDiagram from '../../src/extra/fromDiagram'; import * as assert from 'assert'; @@ -51,17 +49,18 @@ describe('Stream.prototype.flatten', () => { it('should return a flat stream with correct TypeScript types', (done: any) => { const streamStrings: Stream = Stream.create({ - start: (listener: Listener) => {}, + start: (_listener: Listener) => {}, stop: () => {} }); const streamBooleans: Stream = Stream.create({ - start: (listener: Listener) => {}, + start: (_listener: Listener) => {}, stop: () => {} }); // Type checked by the compiler. Without Stream it does not compile. - const flat: Stream = streamStrings.map(x => streamBooleans).flatten(); + const flat: Stream = streamStrings.map(_x => streamBooleans).flatten(); + flat.drop(0); // no unused variable done(); }); @@ -166,7 +165,7 @@ describe('Stream.prototype.flatten', () => { // a$.withLatestFrom(b$, (a, b) => a + b) const c$ = b$.map(b => - a$.map(a => a + b).debug(a => { innerAEmissions += 1; }) + a$.map(a => a + b).debug(() => { innerAEmissions += 1; }) ).flatten().take(1); let cEmissions = 0; @@ -189,7 +188,7 @@ describe('Stream.prototype.flatten', () => { it('should not error when stopping, and outer stream was empty', (done: any) => { const outer = xs.never(); - const stream = outer.map(x => xs.of(1, 2, 3)).flatten(); + const stream = outer.map(() => xs.of(1, 2, 3)).flatten(); const listener = { next: () => {}, error: () => {}, @@ -209,7 +208,7 @@ describe('Stream.prototype.flatten', () => { const periodic = fromDiagram('---a-b--c----d--e--f----g--h-|', { values: { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 } }); - const stream = outer.map(x => { + const stream = outer.map>(x => { if (x === 'A') { return periodic.map(i => i * 10); } else if (x === 'B') { @@ -335,4 +334,9 @@ describe('Stream.prototype.flatten', () => { }); }); }); -}); + + it.skip('should allow to flatten with inner being a MemoryStream', function() { + // @TODO: actually make this next line compile + // xs.of(xs.of(1).remember()).flatten(); + }) +}); \ No newline at end of file diff --git a/tests/operator/fold.ts b/tests/operator/fold.ts index 6956f55..d81d31d 100644 --- a/tests/operator/fold.ts +++ b/tests/operator/fold.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; @@ -24,7 +22,7 @@ describe('Stream.prototype.fold', () => { it('should propagate user mistakes in accumulate as errors', (done: any) => { const source = xs.periodic(30).take(1); const stream = source.fold( - (x, y) => ( x).toLowerCase(), + x => ( x).toLowerCase(), 0 ); const expected = [0]; diff --git a/tests/operator/imitate.ts b/tests/operator/imitate.ts index edb0cbd..3c7533a 100644 --- a/tests/operator/imitate.ts +++ b/tests/operator/imitate.ts @@ -1,6 +1,4 @@ -/// -/// -import xs, {Producer, Listener, Stream, MemoryStream} from '../../src/index'; +import xs, {Stream, MemoryStream} from '../../src/index'; import delay from '../../src/extra/delay'; import * as assert from 'assert'; diff --git a/tests/operator/last.ts b/tests/operator/last.ts index f646057..fdfd2ad 100644 --- a/tests/operator/last.ts +++ b/tests/operator/last.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; diff --git a/tests/operator/map.ts b/tests/operator/map.ts index 5fdb78c..9cf7e38 100644 --- a/tests/operator/map.ts +++ b/tests/operator/map.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; @@ -85,7 +83,7 @@ describe('Stream.prototype.map', () => { assert.strictEqual(x, expected.shift()); assert.strictEqual(stream['_prod']['out'], stream); }, - error: (err: any) => { + error: () => { errorCalled = true; }, complete: () => { @@ -103,7 +101,7 @@ describe('Stream.prototype.map', () => { const stream = xs.create(); let firstMapCalled = 0; - const source$ = stream.map(x => { + const source$ = stream.map(() => { firstMapCalled += 1; return {a: 10, b: 20, c: 30}; }); @@ -135,7 +133,7 @@ describe('Stream.prototype.map', () => { const stream = xs.create(); let firstMapCalled = 0; - const source$ = stream.filter(x => x !== 42).map(x => { + const source$ = stream.filter(x => x !== 42).map(() => { firstMapCalled += 1; return {a: 10, b: 20, c: 30}; }); diff --git a/tests/operator/mapTo.ts b/tests/operator/mapTo.ts index 7b81696..2ff68dd 100644 --- a/tests/operator/mapTo.ts +++ b/tests/operator/mapTo.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; diff --git a/tests/operator/remember.ts b/tests/operator/remember.ts index de588d4..097a2ec 100644 --- a/tests/operator/remember.ts +++ b/tests/operator/remember.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; function noop() {} diff --git a/tests/operator/replaceError.ts b/tests/operator/replaceError.ts index 4a5031b..66c5822 100644 --- a/tests/operator/replaceError.ts +++ b/tests/operator/replaceError.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream, Producer} from '../../src/index'; import * as assert from 'assert'; @@ -7,7 +5,7 @@ describe('Stream.prototype.replaceError', () => { it('should replace a single error with an array stream', (done: any) => { const source = xs.of('a', 'b', 'c', 2, 'd').map(i => i.toLowerCase()); const other = xs.of(10, 20, 30); - const stream = source.replaceError(err => other); + const stream = source.replaceError(() => other); const expected = ['a', 'b', 'c', 10, 20, 30]; stream.addListener({ @@ -35,7 +33,7 @@ describe('Stream.prototype.replaceError', () => { {type: 'complete'}, ]; - const source = xs.create({ + const source = xs.create({ start: (listener) => { while (events.length > 0) { const event = events.shift(); @@ -54,7 +52,7 @@ describe('Stream.prototype.replaceError', () => { stop: () => void 0, }); - const stream = source.replaceError(err => source); + const stream = source.replaceError(() => source); const expected = [10, 20, 30, 40, 50, 60]; stream.addListener({ @@ -83,7 +81,7 @@ describe('Stream.prototype.replaceError', () => { ]; const source = xs.create(> { on: false, - start: (listener) => { + start(this: Producer & {on: boolean}, listener) { this.on = true; for (let i = 0; i < events.length; i++) { if (!this.on) return; @@ -96,12 +94,12 @@ describe('Stream.prototype.replaceError', () => { } } }, - stop: () => { + stop(this: Producer & {on: boolean}) { this.on = false; }, }); - const stream = source.replaceError(err => source).take(8); + const stream = source.replaceError(() => source).take(8); const expected = [10, 20, 30, 10, 20, 30, 10, 20]; stream.addListener({ @@ -123,7 +121,7 @@ describe('Stream.prototype.replaceError', () => { ); stream.addListener({ - next: (s: string) => done('next should not be called'), + next: () => done('next should not be called'), error: (err) => { assert.notStrictEqual(err.message.match(/is not a function$/), null); done(); @@ -137,7 +135,7 @@ describe('Stream.prototype.replaceError', () => { it('should return a Stream if input stream is a Stream', (done: any) => { const input = xs.of(1, 2, 3); assert.strictEqual(input instanceof Stream, true); - const stream: Stream = input.replaceError(err => xs.never()); + const stream: Stream = input.replaceError(() => xs.never()); assert.strictEqual(stream instanceof Stream, true); done(); }); @@ -145,7 +143,7 @@ describe('Stream.prototype.replaceError', () => { it('should return a MemoryStream if input stream is a MemoryStream', (done: any) => { const input = xs.of(1, 2, 3).remember(); assert.strictEqual(input instanceof MemoryStream, true); - const stream: MemoryStream = input.replaceError(err => xs.never()); + const stream: MemoryStream = input.replaceError(() => xs.never()); assert.strictEqual(stream instanceof MemoryStream, true); done(); }); diff --git a/tests/operator/startWith.ts b/tests/operator/startWith.ts index 0f730c0..23bfa08 100644 --- a/tests/operator/startWith.ts +++ b/tests/operator/startWith.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {MemoryStream} from '../../src/index'; import * as assert from 'assert'; diff --git a/tests/operator/take.ts b/tests/operator/take.ts index 87c6ee5..2e86168 100644 --- a/tests/operator/take.ts +++ b/tests/operator/take.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Stream, MemoryStream} from '../../src/index'; import * as assert from 'assert'; @@ -70,7 +68,7 @@ describe('Stream.prototype.take', () => { const stream = xs.periodic(50).take(0); stream.addListener({ - next: (x: number) => { + next: () => { done('next should not be called'); }, error: (err: any) => done(err), @@ -81,23 +79,26 @@ describe('Stream.prototype.take', () => { }); it('should terminate properly when "next" function recursively calls itself', (done: any) => { + const producer = { - start: (listener: any) => { + listener: null, + start(this: {listener: any}, listener: any) { this.listener = listener; listener.next(1); }, - _n: (value: any) => { + _n(this: {listener: any},value: any) { const listener = this.listener; if (listener) listener.next(value); }, - _e: (value: string) => { + _e(this: {listener: any},value: string) { const listener = this.listener; if (listener) listener.error(value); }, - stop: () => this.listener = null, - listener: null + stop(this: {listener: any}) { + this.listener = null + }, }; - const stream = xs.create(producer); + const stream = xs.create(producer); let nextCount = 0; stream.take(1).addListener({ diff --git a/tests/stream.ts b/tests/stream.ts index a755b81..518706a 100644 --- a/tests/stream.ts +++ b/tests/stream.ts @@ -1,5 +1,3 @@ -/// -/// import xs, {Producer, Listener, Stream} from '../src/index'; import fromDiagram from '../src/extra/fromDiagram'; import * as assert from 'assert'; @@ -78,7 +76,7 @@ describe('Stream', () => { const expected = [10, 20, 30]; let listenerGotEnd: boolean = false; - const stream = xs.create(); + const stream = xs.create(); stream.addListener({ next: (x: number) => { @@ -201,7 +199,7 @@ describe('Stream', () => { it('should synchronously stop producer when completed', (done: any) => { let on = false; - const stream = xs.create({ + const stream = xs.create({ start: (listener) => { on = true; listener.next(10); @@ -248,7 +246,7 @@ describe('Stream', () => { it('should synchronously stop producer when error thrown', (done: any) => { let on = false; - const stream = xs.create({ + const stream = xs.create({ start: (listener) => { on = true; listener.next(10); diff --git a/tests/types.ts b/tests/types.ts index 053f49f..7797e41 100644 --- a/tests/types.ts +++ b/tests/types.ts @@ -1,4 +1,4 @@ import xs from '../src/index'; // can be used as type -type T = xs; +export type T = xs; diff --git a/tsconfig.json b/tsconfig.json index 5b60c1a..5444093 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,10 @@ "inlineSources": true, "declaration": true, "noImplicitAny": true, - "strictNullChecks": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "strict": true, + "moduleResolution": "node", "suppressImplicitAnyIndexErrors": true, "module": "commonjs", "noEmitHelpers": false, @@ -37,7 +40,6 @@ "src/extra/tween.ts", "src/index.ts" ], - "filesGlob": ["typings/index.d.ts", "src/**/*.ts"], "atom": { "rewriteTsconfig": true }