Skip to content

Commit

Permalink
align naming of query-related actions #117
Browse files Browse the repository at this point in the history
new naming:

ApiQueryInitAction
ApiQuerySuccessAction
ApiQueryFailAction
ApiQueryRefreshAction
LocalQueryInitAction
LocalQuerySuccessAction
LocalQueryFailAction
  • Loading branch information
remmeier committed Feb 8, 2017
1 parent 7b1c88d commit dc9982a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 65 deletions.
36 changes: 18 additions & 18 deletions spec/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import {
ApiApplySuccessAction,
ApiApplyFailAction,
ApiRollbackAction,
QueryStoreInitAction,
QueryStoreSuccessAction,
LocalQueryInitAction,
LocalQuerySuccessAction,
DeleteStoreResourceAction,
PatchStoreResourceAction,
PostStoreResourceAction,
RemoveQueryAction,
ClearStoreAction,
CompactStoreAction,
QueryRefreshAction
ApiQueryRefreshAction
} from '../src/actions';

describe('Json Api Actions', () => {
Expand Down Expand Up @@ -118,13 +118,13 @@ describe('Json Api Actions', () => {
});

it('should have a query store init action', () => {
expect(NgrxJsonApiActionTypes.QUERY_STORE_INIT).toBeDefined();
expect(NgrxJsonApiActionTypes.QUERY_STORE_INIT).toBe('QUERY_STORE_INIT');
expect(NgrxJsonApiActionTypes.LOCAL_QUERY_INIT).toBeDefined();
expect(NgrxJsonApiActionTypes.LOCAL_QUERY_INIT).toBe('LOCAL_QUERY_INIT');
});

it('should have a query store success action', () => {
expect(NgrxJsonApiActionTypes.QUERY_STORE_SUCCESS).toBeDefined();
expect(NgrxJsonApiActionTypes.QUERY_STORE_SUCCESS).toBe('QUERY_STORE_SUCCESS');
expect(NgrxJsonApiActionTypes.LOCAL_QUERY_SUCCESS).toBeDefined();
expect(NgrxJsonApiActionTypes.LOCAL_QUERY_SUCCESS).toBe('LOCAL_QUERY_SUCCESS');
});

it('should have a delete store resource action', () => {
Expand Down Expand Up @@ -158,8 +158,8 @@ describe('Json Api Actions', () => {
});

it('should have a query refresh action', () => {
expect(NgrxJsonApiActionTypes.QUERY_REFRESH).toBeDefined();
expect(NgrxJsonApiActionTypes.QUERY_REFRESH).toBe('QUERY_REFRESH');
expect(NgrxJsonApiActionTypes.API_QUERY_REFRESH).toBeDefined();
expect(NgrxJsonApiActionTypes.API_QUERY_REFRESH).toBe('API_QUERY_REFRESH');
});

it('should generate an api create init action using apiCreateInit', () => {
Expand Down Expand Up @@ -257,15 +257,15 @@ describe('Json Api Actions', () => {
expect(action.type).toEqual(NgrxJsonApiActionTypes.API_ROLLBACK);
});

it('should generate a query store init action using QueryStoreInitAction', () => {
let action = new QueryStoreInitAction({});
expect(action.type).toEqual(NgrxJsonApiActionTypes.QUERY_STORE_INIT);
it('should generate a query store init action using LocalQueryInitAction', () => {
let action = new LocalQueryInitAction({});
expect(action.type).toEqual(NgrxJsonApiActionTypes.LOCAL_QUERY_INIT);
expect(action.payload).toEqual({});
});

it('should generate a query store success action using QueryStoreSuccessAction', () => {
let action = new QueryStoreSuccessAction({});
expect(action.type).toEqual(NgrxJsonApiActionTypes.QUERY_STORE_SUCCESS);
it('should generate a query store success action using LocalQuerySuccessAction', () => {
let action = new LocalQuerySuccessAction({});
expect(action.type).toEqual(NgrxJsonApiActionTypes.LOCAL_QUERY_SUCCESS);
expect(action.payload).toEqual({});
});

Expand Down Expand Up @@ -303,8 +303,8 @@ describe('Json Api Actions', () => {
expect(action.type).toEqual(NgrxJsonApiActionTypes.CLEAR_STORE);
});

it('should generate a refresh query action using QueryRefreshAction', () => {
let action = new QueryRefreshAction({});
expect(action.type).toEqual(NgrxJsonApiActionTypes.QUERY_REFRESH);
it('should generate a refresh query action using ApiQueryRefreshAction', () => {
let action = new ApiQueryRefreshAction({});
expect(action.type).toEqual(NgrxJsonApiActionTypes.API_QUERY_REFRESH);
});
});
18 changes: 9 additions & 9 deletions spec/effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import {
ApiDeleteInitAction,
ApiDeleteSuccessAction,
ApiDeleteFailAction,
QueryStoreInitAction,
QueryStoreSuccessAction,
QueryStoreFailAction
LocalQueryInitAction,
LocalQuerySuccessAction,
LocalQueryFailAction
} from '../src/actions';

import {
Expand Down Expand Up @@ -223,32 +223,32 @@ describe('NgrxJsonApiEffects', () => {
expect(res).toBeDefined();
});

it('should respond to successfull QUERY_STORE_INIT action', () => {
it('should respond to successfull LOCAL_QUERY_INIT action', () => {
let res;
let query = {
type: 'Article',
id: '1',
queryId: '11'
}
runner.queue(new QueryStoreInitAction(query));
runner.queue(new LocalQueryInitAction(query));
effects.queryStore$.subscribe(result => {
res = result;
expect(result).toEqual(
new QueryStoreSuccessAction({
new LocalQuerySuccessAction({
jsonApiData: { data: result.payload.jsonApiData.data },
query: query,
}));
});
expect(res).toBeDefined();
});

// it('should respond to failed QUERY_STORE_INIT action', () => {
// it('should respond to failed LOCAL_QUERY_INIT action', () => {
// let res;
// runner.queue(new QueryStoreInitAction(failQuery));
// runner.queue(new LocalQueryInitAction(failQuery));
// effects.queryStore$.subscribe(result => {
// res = result;
// expect(result).toEqual(
// new QueryStoreFailAction(failQuery));
// new LocalQueryFailAction(failQuery));
// });
// expect(res).toBeDefined();
// });
Expand Down
12 changes: 6 additions & 6 deletions spec/reducers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import {
NgrxJsonApiActionTypes,
PatchStoreResourceAction,
PostStoreResourceAction,
QueryRefreshAction,
ApiQueryRefreshAction,
RemoveQueryAction,
QueryStoreSuccessAction,
LocalQuerySuccessAction,
} from '../src/actions';
import {
NgrxJsonApiStore,
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('NgrxJsonApiReducer', () => {
})
});

describe('QUERY_REFRESH action', () => {
describe('API_QUERY_REFRESH action', () => {

let tempState = NgrxJsonApiStoreReducer(state, new ApiReadInitAction({
id: '1',
Expand All @@ -284,7 +284,7 @@ describe('NgrxJsonApiReducer', () => {
expect(tempState.queries['111'].resultIds).toBeDefined();
expect(tempState.queries['111'].meta).toBeDefined();
expect(tempState.queries['111'].links).toBeDefined();
let newState = NgrxJsonApiStoreReducer(tempState, new QueryRefreshAction('111'));
let newState = NgrxJsonApiStoreReducer(tempState, new ApiQueryRefreshAction('111'));
expect(newState.queries['111'].resultIds).toBeUndefined();
expect(newState.queries['111'].meta).toBeUndefined();
expect(newState.queries['111'].links).toBeUndefined();
Expand Down Expand Up @@ -449,7 +449,7 @@ describe('NgrxJsonApiReducer', () => {
});
});

describe('QUERY_STORE_SUCCESS action', () => {
describe('LOCAL_QUERY_SUCCESS action', () => {
let query = {
queryId: '111',
type: 'Article',
Expand All @@ -462,7 +462,7 @@ describe('NgrxJsonApiReducer', () => {
queryId: '111'
});
let tempState = NgrxJsonApiStoreReducer(state, readInitAction);
let newState = NgrxJsonApiStoreReducer(tempState, new QueryStoreSuccessAction({
let newState = NgrxJsonApiStoreReducer(tempState, new LocalQuerySuccessAction({
jsonApiData: testPayload,
query: query
}));
Expand Down
34 changes: 17 additions & 17 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export const NgrxJsonApiActionTypes = {
API_APPLY_SUCCESS: type('API_APPLY_SUCCESS'),
API_APPLY_FAIL: type('API_APPLY_FAIL'),
API_ROLLBACK: type('API_ROLLBACK'),
QUERY_REFRESH: type('QUERY_REFRESH'),
QUERY_STORE_INIT: type('QUERY_STORE_INIT'),
QUERY_STORE_SUCCESS: type('QUERY_STORE_SUCCESS'),
QUERY_STORE_FAIL: type('QUERY_STORE_FAIL'),
API_QUERY_REFRESH: type('API_QUERY_REFRESH'),
LOCAL_QUERY_INIT: type('LOCAL_QUERY_INIT'),
LOCAL_QUERY_SUCCESS: type('LOCAL_QUERY_SUCCESS'),
LOCAL_QUERY_FAIL: type('LOCAL_QUERY_FAIL'),
DELETE_STORE_RESOURCE: type('DELETE_STORE_RESOURCE'),
PATCH_STORE_RESOURCE: type('PATCH_STORE_RESOURCE'),
POST_STORE_RESOURCE: type('POST_STORE_RESOURCE'),
Expand Down Expand Up @@ -139,18 +139,18 @@ export class RemoveQueryAction implements Action {
constructor(public payload: string) { }
}

export class QueryStoreInitAction implements Action {
type = NgrxJsonApiActionTypes.QUERY_STORE_INIT;
export class LocalQueryInitAction implements Action {
type = NgrxJsonApiActionTypes.LOCAL_QUERY_INIT;
constructor(public payload: Query) { }
}

export class QueryStoreSuccessAction implements Action {
type = NgrxJsonApiActionTypes.QUERY_STORE_SUCCESS;
export class LocalQuerySuccessAction implements Action {
type = NgrxJsonApiActionTypes.LOCAL_QUERY_SUCCESS;
constructor(public payload: Payload) { }
}

export class QueryStoreFailAction implements Action {
type = NgrxJsonApiActionTypes.QUERY_STORE_FAIL;
export class LocalQueryFailAction implements Action {
type = NgrxJsonApiActionTypes.LOCAL_QUERY_FAIL;
constructor(public payload: Payload) { }
}

Expand All @@ -164,11 +164,11 @@ export class ClearStoreAction implements Action {
constructor() { }
}

export class QueryRefreshAction implements Action {
type = NgrxJsonApiActionTypes.QUERY_REFRESH;
export class ApiQueryRefreshAction implements Action {
type = NgrxJsonApiActionTypes.API_QUERY_REFRESH;
constructor(public payload: string) {
if (!payload) {
throw new Error('no query id provided for QueryRefreshAction');
throw new Error('no query id provided for ApiQueryRefreshAction');
}
}
}
Expand All @@ -195,9 +195,9 @@ export type NgrxJsonApiActions
| PatchStoreResourceAction
| PostStoreResourceAction
| RemoveQueryAction
| QueryRefreshAction
| QueryStoreInitAction
| QueryStoreSuccessAction
| QueryStoreFailAction
| ApiQueryRefreshAction
| LocalQueryInitAction
| LocalQuerySuccessAction
| LocalQueryFailAction
| CompactStoreAction
| ClearStoreAction;
16 changes: 8 additions & 8 deletions src/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import {
ApiUpdateFailAction,
ApiUpdateSuccessAction,
NgrxJsonApiActionTypes,
QueryStoreSuccessAction,
QueryStoreFailAction,
QueryRefreshAction
LocalQuerySuccessAction,
LocalQueryFailAction,
ApiQueryRefreshAction
} from './actions';
import { NgrxJsonApi } from './api';
import { NgrxJsonApiSelectors } from './selectors';
Expand Down Expand Up @@ -102,18 +102,18 @@ export class NgrxJsonApiEffects implements OnDestroy {
});

@Effect() queryStore$ = this.actions$
.ofType(NgrxJsonApiActionTypes.QUERY_STORE_INIT)
.ofType(NgrxJsonApiActionTypes.LOCAL_QUERY_INIT)
.map<Action, Query>(toPayload)
.mergeMap((query: Query) => {
return this.store
.select(this.selectors.storeLocation)
.let(this.selectors.queryStore$(query))
.map(results => new QueryStoreSuccessAction({
.map(results => new LocalQuerySuccessAction({
jsonApiData: {data: results},
query: query
}))
.catch(error => Observable.of(
new QueryStoreFailAction(this.toErrorPayload(query, error))));
new LocalQueryFailAction(this.toErrorPayload(query, error))));
});

@Effect() deleteResource$ = this.actions$
Expand All @@ -132,7 +132,7 @@ export class NgrxJsonApiEffects implements OnDestroy {
});

@Effect() triggerReadOnQueryRefresh$ = this.actions$
.ofType(NgrxJsonApiActionTypes.QUERY_REFRESH)
.ofType(NgrxJsonApiActionTypes.API_QUERY_REFRESH)
.withLatestFrom(this.store, (action, store) => {
let queryId = action.payload;
let state = store[this.selectors.storeLocation] as NgrxJsonApiStore;
Expand Down Expand Up @@ -168,7 +168,7 @@ export class NgrxJsonApiEffects implements OnDestroy {
}

if (needsRefresh) {
actions.push(new QueryRefreshAction(queryId));
actions.push(new ApiQueryRefreshAction(queryId));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function NgrxJsonApiStoreReducer(state: NgrxJsonApiStore = initialNgrxJso
});
return newState;
}
case NgrxJsonApiActionTypes.QUERY_REFRESH: {
case NgrxJsonApiActionTypes.API_QUERY_REFRESH: {
// clear result ids and wait until new data is fetched (triggered by effect)
newState = Object.assign({}, state, {
queries: clearQueryResult(state.queries, action.payload)
Expand Down Expand Up @@ -174,14 +174,14 @@ export function NgrxJsonApiStoreReducer(state: NgrxJsonApiStore = initialNgrxJso
});
return newState;
}
case NgrxJsonApiActionTypes.QUERY_STORE_INIT: {
case NgrxJsonApiActionTypes.LOCAL_QUERY_INIT: {
let query = action.payload as Query;
newState = Object.assign({}, state, {
queries: updateQueryParams(state.queries, query),
});
return newState;
}
case NgrxJsonApiActionTypes.QUERY_STORE_SUCCESS: {
case NgrxJsonApiActionTypes.LOCAL_QUERY_SUCCESS: {
newState = Object.assign({}, state, {
queries: updateQueryResults(
state.queries,
Expand Down
8 changes: 4 additions & 4 deletions src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
PatchStoreResourceAction,
PostStoreResourceAction,
RemoveQueryAction,
QueryStoreInitAction,
LocalQueryInitAction,
ClearStoreAction,
CompactStoreAction,
QueryRefreshAction
ApiQueryRefreshAction
} from './actions';
import {
NgrxJsonApiStore,
Expand Down Expand Up @@ -84,12 +84,12 @@ export class NgrxJsonApiService {
if (fromServer) {
this.store.dispatch(new ApiReadInitAction(query));
} else {
this.store.dispatch(new QueryStoreInitAction(query));
this.store.dispatch(new LocalQueryInitAction(query));
}
}

public refreshQuery(queryId: string) {
this.store.dispatch(new QueryRefreshAction(queryId));
this.store.dispatch(new ApiQueryRefreshAction(queryId));
}

private removeQuery(queryId: string) {
Expand Down

0 comments on commit dc9982a

Please sign in to comment.