Skip to content

Commit

Permalink
feat(concatWith): adds concatWith (#4988)
Browse files Browse the repository at this point in the history
`concat` operator, not the `concat` static function, is now deprecated, but in favor of `concatWith`.

NOTE: First real usage of `TestScheduler` run mode in library. Enabled me to format the document with Prettier :)
  • Loading branch information
benlesh authored Oct 15, 2019
1 parent 865b7d3 commit dc89736
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 40 deletions.
31 changes: 21 additions & 10 deletions spec-dtslint/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ export class H { h = 0; }
export class I { i = 0; }
export class J { j = 0; }

export const a = of(new A());
export const b = of(new B());
export const c = of(new C());
export const d = of(new D());
export const e = of(new E());
export const f = of(new F());
export const g = of(new G());
export const h = of(new H());
export const i = of(new I());
export const j = of(new J());
export const a = new A();
export const b = new B();
export const c = new C();
export const d = new D();
export const e = new E();
export const f = new F();
export const g = new G();
export const h = new H();
export const i = new I();
export const j = new J();

export const a$ = of(new A());
export const b$ = of(new B());
export const c$ = of(new C());
export const d$ = of(new D());
export const e$ = of(new E());
export const f$ = of(new F());
export const g$ = of(new G());
export const h$ = of(new H());
export const i$ = of(new I());
export const j$ = of(new J());
62 changes: 62 additions & 0 deletions spec-dtslint/operators/concatWith-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { of } from 'rxjs';
import { concatWith } from 'rxjs/operators';
import { a, b$, c$, d$, e$ } from 'helpers';

it('should support rest params', () => {
const arr = [b$, c$];
const o = of(a).pipe(concatWith(...arr)); // $ExpectType Observable<A | B | C>
const o2 = of(a).pipe(concatWith(d$, ...arr, e$)); // $ExpectType Observable<A | B | C | D | E>
});

it('should infer correctly', () => {
const o = of(1, 2, 3).pipe(concatWith()); // $ExpectType Observable<number>
});

it('should support one argument', () => {
const o = of(1, 2, 3).pipe(concatWith(of(1))); // $ExpectType Observable<number>
});

it('should support two arguments', () => {
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2))); // $ExpectType Observable<number>
});

it('should support three arguments', () => {
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3))); // $ExpectType Observable<number>
});

it('should support four arguments', () => {
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4))); // $ExpectType Observable<number>
});

it('should support five arguments', () => {
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4), of(5))); // $ExpectType Observable<number>
});

it('should support six arguments', () => {
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4), of(5), of(6))); // $ExpectType Observable<number>
});

it('should support six or more arguments', () => {
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4), of(5), of(6), of(7), of(8), of(9))); // $ExpectType Observable<number>
});

it('should support promises', () => {
const o = of(1, 2, 3).pipe(concatWith(Promise.resolve(4))); // $ExpectType Observable<number>
});

it('should support arrays', () => {
const o = of(1, 2, 3).pipe(concatWith([4, 5])); // $ExpectType Observable<number>
});

it('should support iterables', () => {
const o = of(1, 2, 3).pipe(concatWith('foo')); // $ExpectType Observable<string | number>
});

it('should infer correctly with multiple types', () => {
const o = of(1, 2, 3).pipe(concatWith(of('foo'), Promise.resolve([1]), of(6))); // $ExpectType Observable<string | number | number[]>
});

it('should enforce types', () => {
const o = of(1, 2, 3).pipe(concatWith(5)); // $ExpectError
const p = of(1, 2, 3).pipe(concatWith(of(5), 6)); // $ExpectError
});
42 changes: 21 additions & 21 deletions spec-dtslint/operators/merge-spec.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
import { of, asyncScheduler } from 'rxjs';
import { asyncScheduler } from 'rxjs';
import { merge } from 'rxjs/operators';
import { A, B, C, D, E, F, G, a, b, c, d, e, f, g } from '../helpers';
import { a$, b$, c$, d$, e$, f$} from '../helpers';

it('should accept no parameter', () => {
const res = a.pipe(merge()); // $ExpectType Observable<A>
const res = a$.pipe(merge()); // $ExpectType Observable<A>
});

it('should infer correctly with scheduler param', () => {
const res = a.pipe(merge(asyncScheduler)); // $ExpectType Observable<A>
const res = a$.pipe(merge(asyncScheduler)); // $ExpectType Observable<A>
});

it('should infer correctly with concurrent param', () => {
const res = a.pipe(merge(3)); // $ExpectType Observable<A>
const res = a$.pipe(merge(3)); // $ExpectType Observable<A>
});

it('should infer correctly with concurrent and scheduler param', () => {
const res = a.pipe(merge(3, asyncScheduler)); // $ExpectType Observable<A>
const res = a$.pipe(merge(3, asyncScheduler)); // $ExpectType Observable<A>
});

it('should infer correctly with 1 Observable param', () => {
const res = a.pipe(merge(b)); // $ExpectType Observable<A | B>
const res = a$.pipe(merge(b$)); // $ExpectType Observable<A | B>
});

it('should infer correctly with 2 Observable param', () => {
const res = a.pipe(merge(b, c)); // $ExpectType Observable<A | B | C>
const res = a$.pipe(merge(b$, c$)); // $ExpectType Observable<A | B | C>
});

it('should infer correctly with 3 Observable param', () => {
const res = a.pipe(merge(b, c, d)); // $ExpectType Observable<A | B | C | D>
const res = a$.pipe(merge(b$, c$, d$)); // $ExpectType Observable<A | B | C | D>
});

it('should infer correctly with 4 Observable param', () => {
const res = a.pipe(merge(b, c, d, e)); // $ExpectType Observable<A | B | C | D | E>
const res = a$.pipe(merge(b$, c$, d$, e$)); // $ExpectType Observable<A | B | C | D | E>
});

it('should infer correctly with 5 Observable param', () => {
const res = a.pipe(merge(b, c, d, e, f)); // $ExpectType Observable<A | B | C | D | E | F>
const res = a$.pipe(merge(b$, c$, d$, e$, f$)); // $ExpectType Observable<A | B | C | D | E | F>
});

it('should infer correctly with 1 Observable and concurrent param', () => {
const res = a.pipe(merge(b, 1)); // $ExpectType Observable<A | B>
const res = a$.pipe(merge(b$, 1)); // $ExpectType Observable<A | B>
});

it('should infer correctly with 2 Observable and concurrent param', () => {
const res = a.pipe(merge(b, c, 1)); // $ExpectType Observable<A | B | C>
const res = a$.pipe(merge(b$, c$, 1)); // $ExpectType Observable<A | B | C>
});

it('should infer correctly with 3 Observable and concurrent param', () => {
const res = a.pipe(merge(b, c, d, 1)); // $ExpectType Observable<A | B | C | D>
const res = a$.pipe(merge(b$, c$, d$, 1)); // $ExpectType Observable<A | B | C | D>
});

it('should infer correctly with 4 Observable and concurrent param', () => {
const res = a.pipe(merge(b, c, d, e, 1)); // $ExpectType Observable<A | B | C | D | E>
const res = a$.pipe(merge(b$, c$, d$, e$, 1)); // $ExpectType Observable<A | B | C | D | E>
});

it('should infer correctly with 5 Observable and concurrent param', () => {
const res = a.pipe(merge(b, c, d, e, f, 1)); // $ExpectType Observable<A | B | C | D | E | F>
const res = a$.pipe(merge(b$, c$, d$, e$, f$, 1)); // $ExpectType Observable<A | B | C | D | E | F>
});

it('should infer correctly with 1 Observable, concurrent, and scheduler param', () => {
const res = a.pipe(merge(b, 1, asyncScheduler)); // $ExpectType Observable<A | B>
const res = a$.pipe(merge(b$, 1, asyncScheduler)); // $ExpectType Observable<A | B>
});

it('should infer correctly with 2 Observable, concurrent, and scheduler param', () => {
const res = a.pipe(merge(b, c, 1, asyncScheduler)); // $ExpectType Observable<A | B | C>
const res = a$.pipe(merge(b$, c$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C>
});

it('should infer correctly with 3 Observable, concurrent, and scheduler param', () => {
const res = a.pipe(merge(b, c, d, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D>
const res = a$.pipe(merge(b$, c$, d$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D>
});

it('should infer correctly with 4 Observable, concurrent, and scheduler param', () => {
const res = a.pipe(merge(b, c, d, e, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E>
const res = a$.pipe(merge(b$, c$, d$, e$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E>
});

it('should infer correctly with 5 Observable, concurrent, and scheduler param', () => {
const res = a.pipe(merge(b, c, d, e, f, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E | F>
const res = a$.pipe(merge(b$, c$, d$, e$, f$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E | F>
});

// TODO: Fix this when the both merge operator and merge creator function has been fix
Expand Down
16 changes: 16 additions & 0 deletions spec/helpers/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { root } from 'rxjs/internal/util/root';
import { observable } from 'rxjs/internal/symbol/observable';
import { iterator } from 'rxjs/internal/symbol/iterator';
import * as sinon from 'sinon';
import { expect } from 'chai';

export function lowerCaseO<T>(...args: Array<any>): Observable<T> {
const o = {
Expand Down Expand Up @@ -47,6 +48,21 @@ export const createObservableInputs = <T>(value: T) => of(
} as any
) as Observable<ObservableInput<T>>;

/**
* Used to signify no subscriptions took place to `expectSubscriptions` assertions.
*/
export const NO_SUBS: string[] = [];

/**
* Does a deep equality assertion. Used to set up {@link TestScheduler}, so that
* trees of marbles can be compared.
* @param actual The value to run the expectation against.
* @param expected The value expected.
*/
export function assertDeepEquals (actual: any, expected: any) {
expect(actual).to.deep.equal(expected);
}

global.__root__ = root;

let _raf: any;
Expand Down
Loading

1 comment on commit dc89736

@Ash-kosakyan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apres

Please sign in to comment.