Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subscribeToMore function #5

Merged
merged 1 commit into from
Oct 26, 2016
Merged
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
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