Skip to content

Commit

Permalink
Add subscribeToMore function (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Oct 26, 2016
1 parent 9f2a800 commit b252d83
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### vNEXT

- Add `subscribeToMore` function [PR #5](https://github.com/kamilkisiela/apollo-client-rxjs/pull/5)
- Added support for ApolloClient `v0.5.0` [PR #4](https://github.com/kamilkisiela/apollo-client-rxjs/pull/4)
- BREAKING CHANGE No longer support ApolloClient `v0.4.X` [PR #4](https://github.com/kamilkisiela/apollo-client-rxjs/pull/4)

Expand Down
13 changes: 4 additions & 9 deletions src/RxObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ export class RxObservableQuery<T> extends Observable<T> {
}

public updateQuery(mapFn: any): void {
this.checkMethod('updateQuery');
this.getObservableQuery().updateQuery(mapFn);
}

public subscribeToMore(options: any): () => void {
return this.getObservableQuery().subscribeToMore(options);
}

// where magic happens

public _subscribe(subscriber: Subscriber<T>) {
Expand All @@ -73,12 +76,4 @@ export class RxObservableQuery<T> extends Observable<T> {

return this.apollo as ObservableQuery;
}

private checkMethod(method: string): void {
const obsQuery = this.getObservableQuery();

if (typeof obsQuery[method] === 'undefined') {
throw new Error(`Method '${method}' is not available in your version of ApolloClient`);
}
}
}
9 changes: 9 additions & 0 deletions tests/RxObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ describe('RxObservableQuery', () => {
assert.equal(promise, 'promise');
});

it('should be able to subscribeToMore', () => {
const stubbed = stub(obsQuery, 'subscribeToMore').returns('fn');
const options = {};
const fn = rxObsQuery.subscribeToMore(options);

assert.deepEqual(stubbed.args[0], [options]);
assert.equal(fn, 'fn');
});

it('should be able to updateQuery', () => {
const stubbed = stub(obsQuery, 'updateQuery').returns('void');
const mapFn = () => {
Expand Down

0 comments on commit b252d83

Please sign in to comment.