Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions src/decorators/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'rxjs/add/operator/map';
import { NgRedux } from '../components/ng-redux';
import { RootStore } from '../components/root-store';
import { select, select$ } from './select';
import { map } from 'rxjs/operators';

interface IAppState {
foo: string;
Expand Down Expand Up @@ -158,18 +159,49 @@ describe('Select decorators', () => {
describe('@select$', () => {
const transformer = (baz$: Observable<number>) => baz$.map(baz => 2 * baz);

it('applies a transformer to the observable', done => {
class MockClass {
@select$('baz', transformer)
baz$: Observable<number>;
}
const mockInstance = new MockClass();
describe('when passed a string', () => {
it('applies a transformer to the observable', done => {
class MockClass {
@select$('baz', transformer)
baz$: Observable<number>;
}
const mockInstance = new MockClass();

mockInstance.baz$
.take(2)
.toArray()
.subscribe(
values => expect(values).toEqual([-2, 10]), undefined, done);
ngRedux.dispatch({ type: 'nvm', payload: 5 });
});
});

describe('when passed a function', () => {

const toStringTrans = (baz$: Observable<number>): Observable<string> =>
baz$.pipe(
map((baz: number) => 2 * baz),
map((baz: number) => '' + baz)
);

mockInstance.baz$
.take(2)
.toArray()
.subscribe(values => expect(values).toEqual([-2, 10]), undefined, done);
ngRedux.dispatch({ type: 'nvm', payload: 5 });
const selector = function (state: IAppState): number {
return state.baz;
};

it('applies a transformer to the observable', done => {
class MockClass {
@select$(selector, toStringTrans)
baz$: Observable<string>;
}
const mockInstance = new MockClass();

mockInstance.baz$
.take(2)
.toArray()
.subscribe(
values => expect(values).toEqual(['-2', '10']), undefined, done);
ngRedux.dispatch({ type: 'nvm', payload: 5 });
});
});

describe('when passed a comparator', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/decorators/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export function select<T>(
* }
* ```
*/
export function select$<T>(
selector: Selector<any, T>,
transformer: Transformer<any, T>,
export function select$<S, T>(
selector: Selector<any, S>,
transformer: Transformer<S, T>,
comparator?: Comparator
): PropertyDecorator {
return decorate(selector, transformer, comparator);
Expand Down