Skip to content

Commit

Permalink
Remove unused broadcastNewStore and remove unused Redux actions
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj committed Jul 12, 2017
1 parent dbf646c commit bcaaf23
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 203 deletions.
6 changes: 0 additions & 6 deletions src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,7 @@ export default class ApolloClient implements DataProxy {
this.setStore(store);

return (next: any) => (action: any) => {
const previousApolloState = this.queryManager.selectApolloState(store);
const returnValue = next(action);
const newApolloState = this.queryManager.selectApolloState(store);

if (newApolloState !== previousApolloState) {
this.queryManager.broadcastNewStore(store.getState());
}

if (this.devToolsHookCb) {
this.devToolsHookCb({
Expand Down
58 changes: 0 additions & 58 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,60 +39,6 @@ export function isQueryResultAction(action: ApolloAction): action is QueryResult
return action.type === 'APOLLO_QUERY_RESULT';
}

export interface QueryErrorAction {
type: 'APOLLO_QUERY_ERROR';
error: Error;
queryId: string;
requestId: number;
fetchMoreForQueryId?: string;
}

export function isQueryErrorAction(action: ApolloAction): action is QueryErrorAction {
return action.type === 'APOLLO_QUERY_ERROR';
}

export interface QueryInitAction {
type: 'APOLLO_QUERY_INIT';
queryString: string;
document: DocumentNode;
operationName: string | null;
variables: Object;
fetchPolicy: FetchPolicy;
queryId: string;
requestId: number;
storePreviousVariables: boolean;
isRefetch: boolean;
isPoll: boolean;
fetchMoreForQueryId?: string;
metadata: any;
}

export function isQueryInitAction(action: ApolloAction): action is QueryInitAction {
return action.type === 'APOLLO_QUERY_INIT';
}

export interface QueryResultClientAction {
type: 'APOLLO_QUERY_RESULT_CLIENT';
result: ExecutionResult;
operationName: string | null;
complete: boolean;
queryId: string;
requestId: number;
}

export function isQueryResultClientAction(action: ApolloAction): action is QueryResultClientAction {
return action.type === 'APOLLO_QUERY_RESULT_CLIENT';
}

export interface QueryStopAction {
type: 'APOLLO_QUERY_STOP';
queryId: string;
}

export function isQueryStopAction(action: ApolloAction): action is QueryStopAction {
return action.type === 'APOLLO_QUERY_STOP';
}

// contains both the original value of a query and a reducer to transform
// the query during an update
export type QueryWithUpdater = {
Expand Down Expand Up @@ -198,10 +144,6 @@ export function isWriteAction(action: ApolloAction): action is WriteAction {

export type ApolloAction =
QueryResultAction |
QueryErrorAction |
QueryInitAction |
QueryResultClientAction |
QueryStopAction |
MutationInitAction |
MutationResultAction |
MutationErrorAction |
Expand Down
47 changes: 0 additions & 47 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ export class QueryManager {
}
}

// Called from middleware
public broadcastNewStore(store: any) {
this.broadcastQueries();
}

public mutate<T>({
mutation,
variables,
Expand Down Expand Up @@ -463,24 +458,6 @@ export class QueryManager {

this.broadcastQueries();

this.store.dispatch({
type: 'APOLLO_QUERY_INIT',
queryString,
document: queryDoc,
operationName: getOperationName(queryDoc),
variables,
fetchPolicy,
queryId,
requestId,
// we store the old variables in order to trigger "loading new variables"
// state if we know we will go to the server
storePreviousVariables: shouldFetch,
isPoll: fetchType === FetchType.poll,
isRefetch: fetchType === FetchType.refetch,
fetchMoreForQueryId,
metadata,
});

this.lastRequestId[queryId] = requestId;

// If there is no part of the query we need to fetch from the server (or,
Expand All @@ -489,17 +466,6 @@ export class QueryManager {
if (shouldDispatchClientResult) {
this.queryStore.markQueryResultClient(queryId, !shouldFetch);
this.broadcastQueries();

this.store.dispatch({
type: 'APOLLO_QUERY_RESULT_CLIENT',
result: { data: storeResult },
variables,
document: queryDoc,
operationName: getOperationName(queryDoc),
complete: !shouldFetch,
queryId,
requestId,
});
}

if (shouldFetch) {
Expand All @@ -516,14 +482,6 @@ export class QueryManager {
throw error;
} else {
if (requestId >= (this.lastRequestId[queryId] || 1)) {
this.store.dispatch({
type: 'APOLLO_QUERY_ERROR',
error,
queryId,
requestId,
fetchMoreForQueryId,
});

this.queryStore.markQueryError(queryId, error, fetchMoreForQueryId);
this.broadcastQueries();
}
Expand Down Expand Up @@ -791,11 +749,6 @@ export class QueryManager {
public stopQueryInStore(queryId: string) {
this.queryStore.stopQuery(queryId);
this.broadcastQueries();

this.store.dispatch({
type: 'APOLLO_QUERY_STOP',
queryId,
});
}

public getApolloState(): Store {
Expand Down
77 changes: 0 additions & 77 deletions test/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1518,83 +1518,6 @@ describe('QueryManager', () => {
);
});

it('does not call broadcastNewStore when Apollo state is not affected by an action', () => {
const query = gql`
query fetchLuke($id: String) {
people_one(id: $id) {
name
}
}
`;

const variables = {
id: '1',
};

const data1 = {
people_one: {
name: 'Luke Skywalker',
},
};

const data2 = {
people_one: {
name: 'Luke Skywalker has a new name',
},
};

function testReducer (state = false, action: any): boolean {
if (action.type === 'TOGGLE') {
return true;
}
return state;
}
const client = new ApolloClient();
const store = createStore(
combineReducers({
test: testReducer,
apollo: client.reducer() as any, // XXX see why this type fails
}),
applyMiddleware(client.middleware()),
);
const qm = createQueryManager({
networkInterface: mockNetworkInterface(
{
request: { query, variables },
result: { data: data1 },
},
{
request: { query, variables },
result: { data: data2 },
},
),
store: store,
});

const observable = qm.watchQuery({ query, variables, notifyOnNetworkStatusChange: false });

return observableToPromise({ observable },
(result) => {
assert.deepEqual(result.data, data1);
observable.refetch();
},
(result) => {
assert.deepEqual(result.data, data2);

// here's the actual test. Everything else is just setup.
let called = false;
client.queryManager.broadcastNewStore = (s: any) => {
called = true;
};
store.dispatch({
type: 'TOGGLE',
});
assert.equal((store.getState() as any).test, true, 'test state should have been updated');
assert.equal(called, false, 'broadcastNewStore should not have been called');
},
);
});

it(`doesn't return data while query is loading`, () => {
const query1 = gql`
{
Expand Down
15 changes: 0 additions & 15 deletions test/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ describe('createApolloStore', () => {
initialState,
});

store.dispatch({
type: 'APOLLO_QUERY_INIT',
queryId: 'test.0',
queryString: '',
document: queryDocument,
operationName: getOperationName(queryDocument),
variables: {},
fetchPolicy: 'cache-first',
requestId: 1,
storePreviousVariables: false,
isPoll: false,
isRefetch: false,
metadata: null,
});

store.dispatch({
type: 'APOLLO_STORE_RESET',
observableQueryIds: ['test.0'],
Expand Down

0 comments on commit bcaaf23

Please sign in to comment.