Skip to content

Commit

Permalink
Merge pull request #395 from apollostack/set_polling_interval
Browse files Browse the repository at this point in the history
Add batcherPollInterval as an option to ApolloClient
  • Loading branch information
Sashko Stubailo authored Jul 13, 2016
2 parents 49dae6b + ce413e3 commit 963af2a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 3 to 6 months), to signal the start of a more stable API.

### vNEXT
- Added the `batchInterval` option to ApolloClient that allows you to specify the width of the batching interval as per your app's needs. [Issue #394](https://github.com/apollostack/apollo-client/issues/394) and [PR #395](https://github.com/apollostack/apollo-client/pull/395).

- Stringify `storeObj` for error message in `diffFieldAgainstStore`.
- Fix map function returning `undefined` in `removeRefsFromStoreObj`. [PR #393](https://github.com/apollostack/apollo-client/pull/393)
Expand Down
8 changes: 5 additions & 3 deletions src/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class QueryManager {

private scheduler: QueryScheduler;
private batcher: QueryBatcher;
private batcherPollInterval = 10;
private batchInterval: number;

// A map going from an index (i.e. just like an array index, except that we can remove
// some of them) to a promise that has not yet been resolved. We use this to keep
Expand All @@ -167,12 +167,14 @@ export class QueryManager {
reduxRootKey,
queryTransformer,
shouldBatch = false,
batchInterval = 10,
}: {
networkInterface: NetworkInterface,
store: ApolloStore,
reduxRootKey: string,
queryTransformer?: QueryTransformer,
shouldBatch?: Boolean,
batchInterval?: number,
}) {
// XXX this might be the place to do introspection for inserting the `id` into the query? or
// is that the network interface?
Expand All @@ -181,7 +183,7 @@ export class QueryManager {
this.reduxRootKey = reduxRootKey;
this.queryTransformer = queryTransformer;
this.pollingTimers = {};

this.batchInterval = batchInterval;
this.queryListeners = {};

this.scheduler = new QueryScheduler({
Expand All @@ -193,7 +195,7 @@ export class QueryManager {
networkInterface: this.networkInterface,
});

this.batcher.start(this.batcherPollInterval);
this.batcher.start(this.batchInterval);
this.fetchQueryPromises = {};
this.observableQueries = {};

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default class ApolloClient {
public shouldForceFetch: boolean;
public dataId: IdGetter;
public fieldWithArgs: (fieldName: string, args?: Object) => string;
public batchInterval: number;

constructor({
networkInterface,
Expand All @@ -161,6 +162,7 @@ export default class ApolloClient {
ssrMode = false,
ssrForceFetchDelay = 0,
mutationBehaviorReducers = {} as MutationBehaviorReducerMap,
batchInterval,
}: {
networkInterface?: NetworkInterface,
reduxRootKey?: string,
Expand All @@ -171,6 +173,7 @@ export default class ApolloClient {
ssrMode?: boolean,
ssrForceFetchDelay?: number
mutationBehaviorReducers?: MutationBehaviorReducerMap,
batchInterval?: number,
} = {}) {
this.reduxRootKey = reduxRootKey ? reduxRootKey : 'apollo';
this.initialState = initialState ? initialState : {};
Expand All @@ -181,6 +184,7 @@ export default class ApolloClient {
this.shouldForceFetch = !(ssrMode || ssrForceFetchDelay > 0);
this.dataId = dataIdFromObject;
this.fieldWithArgs = storeKeyNameFromFieldNameAndArgs;
this.batchInterval = batchInterval;

if (ssrForceFetchDelay) {
setTimeout(() => this.shouldForceFetch = true, ssrForceFetchDelay);
Expand Down Expand Up @@ -281,6 +285,7 @@ export default class ApolloClient {
store,
queryTransformer: this.queryTransformer,
shouldBatch: this.shouldBatch,
batchInterval: this.batchInterval,
});
};
}

0 comments on commit 963af2a

Please sign in to comment.