Skip to content

Commit

Permalink
web: create effects using "createEffect" rather than @effect
Browse files Browse the repository at this point in the history
* that improves type-safety
  • Loading branch information
devDefiWeb committed Jun 17, 2019
1 parent 612ae35 commit 29e2740
Show file tree
Hide file tree
Showing 6 changed files with 953 additions and 910 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "electron-mail",
"description": "Unofficial desktop app for ProtonMail and Tutanota E2EE email providers",
"version": "3.5.0",
"version": "3.5.1",
"author": "Vladimir Yakovlev <desktop-app@protonmail.ch>",
"license": "MIT",
"homepage": "https://github.com/vladimiry/ElectronMail",
Expand Down
857 changes: 434 additions & 423 deletions src/web/src/app/_accounts/accounts.effects.ts

Large diffs are not rendered by default.

173 changes: 93 additions & 80 deletions src/web/src/app/_core/navigation.effects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Actions, Effect} from "@ngrx/effects";
import {Actions, createEffect} from "@ngrx/effects";
import {EMPTY, from, of} from "rxjs";
import {Injectable, NgZone} from "@angular/core";
import {Location} from "@angular/common";
Expand All @@ -13,99 +13,112 @@ const _logger = getZoneNameBoundWebLogger("[navigation.effects.ts]");

@Injectable()
export class NavigationEffects {
@Effect({dispatch: false})
navigate$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Go),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
tap(({payload, logger}) => {
const {path, extras, queryParams} = payload;
navigate$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Go),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
tap(({payload, logger}) => {
const {path, extras, queryParams} = payload;

// WARN: privacy note, do not log "queryParams" as it might be filled with sensitive data (like "login"/"user name")
logger.verbose(JSON.stringify({path, extras}));
// WARN: privacy note, do not log "queryParams" as it might be filled with sensitive data (like "login"/"user name")
logger.verbose(JSON.stringify({path, extras}));

this.ngZone.run(async () => {
// tslint:disable-next-line:no-floating-promises
await this.router.navigate(path, {queryParams, ...extras});
});
}),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
);

@Effect({dispatch: false})
navigateBack$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Back),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
tap(() => this.location.back()),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
this.ngZone.run(async () => {
// tslint:disable-next-line:no-floating-promises
await this.router.navigate(path, {queryParams, ...extras});
});
}),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
),
{dispatch: false},
);

@Effect({dispatch: false})
navigateForward$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Forward),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
tap(() => this.location.forward()),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
navigateBack$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Back),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
tap(() => this.location.back()),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
),
{dispatch: false},
);

@Effect()
toggleBrowserWindow$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.ToggleBrowserWindow),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(({payload}) => from(this.electronService.ipcMainClient()("toggleBrowserWindow")(payload)).pipe(
mergeMap(() => EMPTY),
navigateForward$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Forward),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
tap(() => this.location.forward()),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
)));
),
{dispatch: false},
);

@Effect()
openAboutWindow$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.OpenAboutWindow),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => from(this.electronService.ipcMainClient()("openAboutWindow")()).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
)));
toggleBrowserWindow$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.ToggleBrowserWindow),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(({payload}) => from(this.electronService.ipcMainClient()("toggleBrowserWindow")(payload)).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
))),
);

@Effect()
openExternal$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.OpenExternal),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(({payload}) => from(this.electronService.ipcMainClient()("openExternal")({url: payload.url})).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
)));
openAboutWindow$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.OpenAboutWindow),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => from(this.electronService.ipcMainClient()("openAboutWindow")()).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
))),
);

@Effect()
openSettingsFolder$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.OpenSettingsFolder),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => from(this.electronService.ipcMainClient()("openSettingsFolder")()).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
)));
openExternal$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.OpenExternal),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(({payload}) => from(this.electronService.ipcMainClient()("openExternal")({url: payload.url})).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
)),
),
);

@Effect()
logout$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Logout),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => {
return from(this.electronService.ipcMainClient()("logout")()).pipe(
concatMap(() => {
setTimeout(() => window.location.reload(), 0);
return EMPTY;
}),
openSettingsFolder$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.OpenSettingsFolder),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => from(this.electronService.ipcMainClient()("openSettingsFolder")()).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
);
}),
))),
);

@Effect()
quit$ = this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Quit),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => from(this.electronService.ipcMainClient()("quit")()).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
)));
logout$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Logout),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => {
return from(this.electronService.ipcMainClient()("logout")()).pipe(
concatMap(() => {
setTimeout(() => window.location.reload(), 0);
return EMPTY;
}),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
);
}),
),
);

quit$ = createEffect(
() => this.actions$.pipe(
unionizeActionFilter(NAVIGATION_ACTIONS.is.Quit),
map(logActionTypeAndBoundLoggerWithActionType({_logger})),
concatMap(() => from(this.electronService.ipcMainClient()("quit")()).pipe(
mergeMap(() => EMPTY),
catchError((error) => of(NOTIFICATION_ACTIONS.Error(error))),
))),
);

constructor(
private electronService: ElectronService,
Expand Down

0 comments on commit 29e2740

Please sign in to comment.