Skip to content

Commit

Permalink
Avoid unnecessary checking for undefined client.queryManager.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Apr 16, 2019
1 parent 8087830 commit 112493b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
27 changes: 6 additions & 21 deletions packages/apollo-client/src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,7 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
* to dispose of this `ApolloClient` instance.
*/
public stop() {
if (this.queryManager) {
this.queryManager.stop();
}
this.queryManager.stop();
}

/**
Expand Down Expand Up @@ -505,29 +503,18 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
*/
public resetStore(): Promise<ApolloQueryResult<any>[] | null> {
return Promise.resolve()
.then(() => {
return this.queryManager
? this.queryManager.clearStore()
: Promise.resolve(null);
})
.then(() => this.queryManager.clearStore())
.then(() => Promise.all(this.resetStoreCallbacks.map(fn => fn())))
.then(() => {
return this.queryManager && this.queryManager.reFetchObservableQueries
? this.queryManager.reFetchObservableQueries()
: Promise.resolve(null);
});
.then(() => this.queryManager.reFetchObservableQueries());
}

/**
* Remove all data from the store. Unlike `resetStore`, `clearStore` will
* not refetch any active queries.
*/
public clearStore(): Promise<any | null> {
const { queryManager } = this;
public clearStore(): Promise<any[]> {
return Promise.resolve()
.then(() =>
queryManager ? queryManager.clearStore() : Promise.resolve(null),
)
.then(() => this.queryManager.clearStore())
.then(() => Promise.all(this.clearStoreCallbacks.map(fn => fn())));
}

Expand Down Expand Up @@ -570,9 +557,7 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
public reFetchObservableQueries(
includeStandby?: boolean,
): Promise<ApolloQueryResult<any>[]> | Promise<null> {
return this.queryManager
? this.queryManager.reFetchObservableQueries(includeStandby)
: Promise.resolve(null);
return this.queryManager.reFetchObservableQueries(includeStandby);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-client/src/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,7 @@ describe('client', () => {
cache: new InMemoryCache(),
});
client.queryManager = {
reFetchObservableQueries() {},
clearStore: () => {
done();
},
Expand Down

0 comments on commit 112493b

Please sign in to comment.