Skip to content

Commit

Permalink
Updated the ngrx/store and ngrx/effects packages.
Browse files Browse the repository at this point in the history
Added queryActions in query effects.
  • Loading branch information
imolorhe committed Jul 20, 2017
1 parent aa2ee76 commit d5c5da8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"@ngrx/core": "^1.2.0",
"@ngrx/effects": "^2.0.3",
"@ngrx/store": "^2.2.2",
"@ngrx/effects": "^2.0.4",
"@ngrx/store": "^2.2.3",
"@ngrx/store-devtools": "^3.2.4",
"body-parser": "^1.17.1",
"codemirror": "^5.25.0",
Expand Down
21 changes: 17 additions & 4 deletions src/app/actions/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export class SetQueryResultAction implements Action {
export class PrettifyQueryAction implements Action {
readonly type = PRETTIFY_QUERY;

constructor(public windowId: string) {}
constructor(public windowId: string, public payload?) {}
}

export class SendQueryRequestAction implements Action {
readonly type = SEND_QUERY_REQUEST;

constructor(public windowId: string) {}
constructor(public windowId: string, public payload?) {}
}

export class SetResponseStatsAction implements Action {
Expand All @@ -65,17 +65,30 @@ export class SetResponseStatsAction implements Action {
export class CancelQueryRequestAction implements Action {
readonly type = CANCEL_QUERY_REQUEST;

constructor(public windowId: string) {}
constructor(public windowId: string, public payload?) {}
}

export class HideUrlAlertAction implements Action {
readonly type = HIDE_URL_ALERT;

constructor(public windowId: string) {}
constructor(public windowId: string, public payload?) {}
}

export class ShowUrlAlertAction implements Action {
readonly type = SHOW_URL_ALERT;

constructor(public payload: any, public windowId: string) {}
}

export type Action =
SetUrlAction |
SetUrlFromDbAction |
SetQueryAction |
SetQueryFromDbAction |
SetQueryResultAction |
PrettifyQueryAction |
SendQueryRequestAction |
SetResponseStatsAction |
CancelQueryRequestAction |
HideUrlAlertAction |
ShowUrlAlertAction;
22 changes: 11 additions & 11 deletions src/app/effects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class QueryEffects {
// with the specified headers and variables
sendQueryRequest$: Observable<Action> = this.actions$
.ofType(queryActions.SEND_QUERY_REQUEST, queryActions.CANCEL_QUERY_REQUEST)
.withLatestFrom(this.store, (action, state) => {
.withLatestFrom(this.store, (action: queryActions.Action, state) => {
return { data: state.windows[action.windowId], windowId: action.windowId, action };
})
.do((response) => {
Expand Down Expand Up @@ -83,9 +83,9 @@ export class QueryEffects {

@Effect()
// Shows the URL set alert after the URL is set
showUrlSetAlert$: Observable<Action> = this.actions$
showUrlSetAlert$: Observable<queryActions.Action> = this.actions$
.ofType(queryActions.SET_URL)
.do((data) => {
.do((data: queryActions.Action) => {
const opts = {
message: 'URL has been set',
success: true
Expand All @@ -99,7 +99,7 @@ export class QueryEffects {

return data;
})
.switchMap((data) => {
.switchMap((data: queryActions.Action) => {
return Observable.timer(3000)
.switchMap(() => Observable.of(new queryActions.HideUrlAlertAction(data.windowId)));
});
Expand All @@ -108,7 +108,7 @@ export class QueryEffects {
// Gets the gql schema after the introspection is set
getGqlSchema$: Observable<Action> = this.actions$
.ofType(gqlSchemaActions.SET_INTROSPECTION, gqlSchemaActions.SET_INTROSPECTION_FROM_DB)
.switchMap((data) => {
.switchMap((data: queryActions.Action) => {
const schema = this.gqlService.getIntrospectionSchema(data.payload);

if (schema) {
Expand All @@ -121,7 +121,7 @@ export class QueryEffects {
@Effect()
saveUrlToDb$: Observable<Action> = this.actions$
.ofType(queryActions.SET_URL)
.map((data) => {
.map((data: queryActions.Action) => {
this.queryService.storeUrl(data.payload, data.windowId);
return new dbActions.SaveUrlSuccessAction();
});
Expand All @@ -131,23 +131,23 @@ export class QueryEffects {
.ofType(queryActions.SET_QUERY)
// Save query after user has stopped typing for 500ms
.debounce(() => Observable.timer(500))
.map(data => {
.map((data: queryActions.Action) => {
this.queryService.storeQuery(data.payload, data.windowId);
return new dbActions.SaveQuerySuccessAction();
});

@Effect()
saveIntrospectionToDb$: Observable<Action> = this.actions$
.ofType(gqlSchemaActions.SET_INTROSPECTION)
.map(data => {
.map((data: queryActions.Action) => {
this.queryService.storeIntrospection(data.payload, data.windowId);
return new dbActions.SaveIntrospectionSuccessAction();
});

@Effect()
getIntrospectionForUrl$: Observable<Action> = this.actions$
getIntrospectionForUrl$: Observable<queryActions.Action> = this.actions$
.ofType(queryActions.SET_URL)
.switchMap(data => {
.switchMap((data: queryActions.Action) => {
if (!data.payload) {
return Observable.empty();
}
Expand All @@ -173,7 +173,7 @@ export class QueryEffects {
})
.map(introspectionData => {
if (!introspectionData) {
return {};
return Observable.empty();
}

this.store.dispatch(new gqlSchemaActions.SetAllowIntrospectionAction(true, data.windowId));
Expand Down

0 comments on commit d5c5da8

Please sign in to comment.