Skip to content

Commit

Permalink
fix(database): call apply instead of call
Browse files Browse the repository at this point in the history
RxJS merge takes a variable number of observables - not an array - so
apply should be called instead of call. Fixed the related test, too.
  • Loading branch information
cartant authored and davideast committed Feb 9, 2017
1 parent 9f3c47b commit 7a85bd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
19 changes: 12 additions & 7 deletions src/database/query_observable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('observeQuery', () => {


it('should omit only the orderBy type of the last emitted orderBy observable', () => {
// TODO: Should we allow re-emitting of the orderBy method?
var nextSpy = jasmine.createSpy('next');
var query = {
orderByKey: new Subject<boolean>(),
Expand All @@ -108,13 +107,19 @@ describe('observeQuery', () => {
});
nextSpy.calls.reset();
query.orderByKey.next(true);
expect(nextSpy).not.toHaveBeenCalled();
// nextSpy.calls.reset();
// query.orderByValue.next(true);
// expect(nextSpy).toHaveBeenCalledWith({orderByValue: true});
// nextSpy.calls.reset();
expect(nextSpy).toHaveBeenCalledWith({
orderByKey: true
});
nextSpy.calls.reset();
query.orderByValue.next(true);
expect(nextSpy).toHaveBeenCalledWith({
orderByValue: true
});
nextSpy.calls.reset();
query.orderByChild.next('foo');
expect(nextSpy).toHaveBeenCalledWith({orderByChild: 'foo'});
expect(nextSpy).toHaveBeenCalledWith({
orderByChild: 'foo'
});
});
});

Expand Down
12 changes: 6 additions & 6 deletions src/database/query_observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export function observeQuery(query: Query): Observable<ScalarQuery> {

return Observable.create((observer: Observer<ScalarQuery>) => {

let obs = getOrderObservables(query) as Observable<OrderBySelection>;
combineLatest.call(obs,
combineLatest.call(
getOrderObservables(query),
getStartAtObservable(query),
getEndAtObservable(query),
getEqualToObservable(query),
Expand Down Expand Up @@ -80,7 +80,7 @@ export function observeQuery(query: Query): Observable<ScalarQuery> {
});
}

export function getOrderObservables(query: Query): Observable<OrderBySelection> | Observable<OrderBySelection | Observable<OrderBySelection>> {
export function getOrderObservables(query: Query): Observable<OrderBySelection> {
var observables = ['orderByChild', 'orderByKey', 'orderByValue', 'orderByPriority']
.map((key: string, option: OrderByOptions) => {
return ({ key, option })
Expand All @@ -93,15 +93,15 @@ export function getOrderObservables(query: Query): Observable<OrderBySelection>
if (observables.length === 1) {
return observables[0];
} else if (observables.length > 1) {
return merge.call(observables[0], observables.slice(1));
return merge.apply(observables[0], observables.slice(1));
} else {
return new Observable<OrderBySelection>(subscriber => {
subscriber.next(null);
});
}
}

export function getLimitToObservables(query: Query): Observable<LimitToSelection> | Observable<LimitToSelection | Observable<LimitToSelection>> {
export function getLimitToObservables(query: Query): Observable<LimitToSelection> {
var observables = ['limitToFirst', 'limitToLast']
.map((key: string, option: LimitToOptions) => ({ key, option }))
.filter(({key, option}: { key: string, option: LimitToOptions }) => !isNil(query[key]))
Expand All @@ -110,7 +110,7 @@ export function getLimitToObservables(query: Query): Observable<LimitToSelection
if (observables.length === 1) {
return observables[0];
} else if (observables.length > 1) {
const mergedObs = merge.call(observables[0], observables.slice(1));
const mergedObs = merge.apply(observables[0], observables.slice(1));
return mergedObs;
} else {
return new Observable<LimitToSelection>(subscriber => {
Expand Down

0 comments on commit 7a85bd2

Please sign in to comment.