Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use createEffect instead of deprecated Effect #2103

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { tap, withLatestFrom } from 'rxjs/operators';

Expand All @@ -9,14 +9,16 @@ import { AppState, getIsI2cDebuggingEnabled, isI2cDebuggingRingBellEnabled } fro

@Injectable()
export class AdvancedSettingsEffects {
@Effect({dispatch: false}) toggleI2cDebugging$ = this.actions$
toggleI2cDebugging$ = createEffect(() => this.actions$
.pipe(
ofType(ActionTypes.toggleI2CDebugging),
withLatestFrom(this.store.select(getIsI2cDebuggingEnabled)),
tap(([, enabled])=>{
this.deviceRendererService.toggleI2cDebugging(enabled);
})
);
),
{dispatch: false}
);

constructor(private actions$: Actions,
private store: Store<AppState>,
Expand Down
35 changes: 22 additions & 13 deletions packages/uhk-web/src/app/store/effects/app-update.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Action, Store } from '@ngrx/store';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { EMPTY, Observable } from 'rxjs';
import { Store } from '@ngrx/store';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { EMPTY } from 'rxjs';
import { first, map, tap, withLatestFrom } from 'rxjs/operators';

import { LogService, NotificationType } from 'uhk-common';
Expand All @@ -20,35 +20,41 @@ import { AppState, isForceUpdate } from '../index';

@Injectable()
export class AppUpdateEffect {
@Effect({ dispatch: false }) appStart$: Observable<Action> = this.actions$
appStart$ = createEffect(() => this.actions$
.pipe(
ofType(ActionTypes.UpdateApp),
first(),
tap(() => {
this.appUpdateRendererService.sendUpdateAndRestartApp();
})
);
),
{ dispatch: false }
);

@Effect({ dispatch: false }) checkForUpdate$ = this.actions$
checkForUpdate$ = createEffect(() => this.actions$
.pipe(
ofType<CheckForUpdateNowAction>(AutoUpdateActionTypes.CheckForUpdateNow),
map(action => action.payload),
tap((allowPrerelease: boolean) => {
this.logService.misc('[AppUpdateEffect] call checkForUpdate');
this.appUpdateRendererService.checkForUpdate(allowPrerelease);
})
);
),
{ dispatch: false }
);

@Effect({ dispatch: false }) forceUpdate$ = this.actions$
forceUpdate$ = createEffect(() => this.actions$
.pipe(
ofType<ForceUpdateAction>(ActionTypes.ForceUpdate),
tap(() => {
this.logService.misc('[AppUpdateEffect] force update agent');
this.appUpdateRendererService.checkForUpdate(false);
})
);
),
{ dispatch: false }
);

@Effect() updateAvailable$ = this.actions$
updateAvailable$ = createEffect(() => this.actions$
.pipe(
ofType<UpdateAvailableAction>(ActionTypes.UpdateAvailable),
withLatestFrom(this.store.select(isForceUpdate)),
Expand All @@ -59,9 +65,11 @@ export class AppUpdateEffect {

return EMPTY;
})
);
),
{ dispatch: false }
);

@Effect() handleError$: Observable<Action> = this.actions$
handleError$ = createEffect(() => this.actions$
.pipe(
ofType<UpdateErrorAction>(ActionTypes.UpdateError),
map(action => action.payload),
Expand All @@ -71,7 +79,8 @@ export class AppUpdateEffect {
message
});
})
);
)
);

constructor(private actions$: Actions,
private appUpdateRendererService: AppUpdateRendererService,
Expand Down
53 changes: 33 additions & 20 deletions packages/uhk-web/src/app/store/effects/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Action, Store } from '@ngrx/store';
import { Actions, createEffect, Effect, ofType } from '@ngrx/effects';
import { Observable } from 'rxjs';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { map, mergeMap, startWith, switchMap, tap, withLatestFrom } from 'rxjs/operators';
import { NotifierService } from 'angular-notifier';

Expand Down Expand Up @@ -41,7 +40,7 @@ import { DataStorageRepositoryService } from '../../services/datastorage-reposit
@Injectable()
export class ApplicationEffects {

@Effect() appStart$: Observable<Action> = this.actions$
appStart$ = createEffect(() => this.actions$
.pipe(
ofType(ActionTypes.AppBootstrapped),
startWith(new AppStartedAction()),
Expand All @@ -67,17 +66,20 @@ export class ApplicationEffects {
})
)
)
);
)
);

@Effect({ dispatch: false }) appStartInfo$: Observable<Action> = this.actions$
appStartInfo$= createEffect(() => this.actions$
.pipe(
ofType(ActionTypes.LoadAppStartInfo),
tap(() => {
this.appRendererService.getAppStartInfo();
})
);
),
{ dispatch: false }
);

@Effect({ dispatch: false }) showNotification$: Observable<Action> = this.actions$
showNotification$ = createEffect(() => this.actions$
.pipe(
ofType<ShowNotificationAction>(ActionTypes.AppShowNotification),
map(action => action.payload),
Expand All @@ -87,9 +89,11 @@ export class ApplicationEffects {
}
this.notifierService.notify(notification.type, notification.message);
})
);
),
{ dispatch: false }
);

@Effect() processStartInfo$: Observable<Action> = this.actions$
processStartInfo$ = createEffect(() => this.actions$
.pipe(
ofType<ProcessAppStartInfoAction>(ActionTypes.AppProcessStartInfo),
map(action => action.payload),
Expand All @@ -101,21 +105,23 @@ export class ApplicationEffects {
new StartConnectionPollerAction()
];
})
);
)
);

@Effect() undoLastNotification$: Observable<Action> = this.actions$
undoLastNotification$ = createEffect(() => this.actions$
.pipe(
ofType<UndoLastAction>(ActionTypes.UndoLast),
map(action => action.payload),
mergeMap((action: Action) => [action, new DismissUndoNotificationAction()])
);
)
);

openConfigFolder$ = createEffect(() => this.actions$.pipe(
ofType(ActionTypes.OpenConfigFolder),
tap(() => this.appRendererService.openConfigFolder())
), { dispatch: false });

@Effect({ dispatch: false }) openUrlInNewWindow$ = this.actions$
openUrlInNewWindow$ = createEffect(() => this.actions$
.pipe(
ofType<OpenUrlInNewWindowAction>(ActionTypes.OpenUrlInNewWindow),
withLatestFrom(this.store.select(runningInElectron)),
Expand All @@ -128,9 +134,11 @@ export class ApplicationEffects {
window.open(url, '_blank');
}
})
);
),
{ dispatch: false }
);

@Effect() saveApplicationSettings$ = this.actions$
saveApplicationSettings$ = createEffect(() => this.actions$
.pipe(
ofType(
ActionTypes.ErrorPanelSizeChanged,
Expand All @@ -148,9 +156,10 @@ export class ApplicationEffects {
map(([, config]) => config),
switchMap((config: ApplicationSettings) => this.dataStorageRepository.saveApplicationSettings(config)),
map(() => new SaveApplicationSettingsSuccessAction())
);
)
);

@Effect({ dispatch: false }) setAppTheme$ = this.actions$
setAppTheme$ = createEffect(() => this.actions$
.pipe(
ofType<SetAppThemeAction>(ActionTypes.SetAppTheme),
map(action => action.payload),
Expand All @@ -159,9 +168,11 @@ export class ApplicationEffects {
(window as any).setUhkTheme(theme);
}
})
);
),
{ dispatch: false }
);

@Effect({ dispatch: false }) navigateTo$ = this.actions$
navigateTo$ = createEffect(() => this.actions$
.pipe(
ofType<NavigateTo>(ActionTypes.NavigateTo),
map(action => action.payload),
Expand All @@ -171,7 +182,9 @@ export class ApplicationEffects {
this.router.navigate(payload.commands, payload.extras);
}, 10);
})
);
),
{ dispatch: false }
);

constructor(private actions$: Actions,
private notifierService: NotifierService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Observable } from 'rxjs';
import { Action } from '@ngrx/store';
import { map } from 'rxjs/operators';
Expand All @@ -17,7 +17,7 @@ import { ShowNotificationAction } from '../actions/app';
@Injectable()
export class AutoUpdateSettingsEffects {

@Effect() sendNotification$: Observable<Action> = this.actions$
sendNotification$: Observable<Action> = createEffect(() => this.actions$
.pipe(
ofType<CheckForUpdateSuccessAction | CheckForUpdateFailedAction>(
ActionTypes.CheckForUpdateFailed, ActionTypes.CheckForUpdateSuccess),
Expand All @@ -28,7 +28,8 @@ export class AutoUpdateSettingsEffects {
message
});
})
);
)
);

constructor(private actions$: Actions) {
}
Expand Down
12 changes: 7 additions & 5 deletions packages/uhk-web/src/app/store/effects/contributors.effect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Action, Store } from '@ngrx/store';

import { from, Observable, of } from 'rxjs';
Expand All @@ -20,7 +20,7 @@ import {

@Injectable()
export class ContributorsEffect {
@Effect() getContributors$: Observable<Action> = this.actions$
getContributors$: Observable<Action> = createEffect(() => this.actions$
.pipe(
ofType<GetAgentContributorsAction>(ActionTypes.GetAgentContributors),
withLatestFrom(this.store.select(contributors)),
Expand All @@ -30,9 +30,10 @@ export class ContributorsEffect {
}
return new AgentContributorsAvailableAction(state.contributors);
})
);
)
);

@Effect() fetchContributors$: Observable<Action> = this.actions$
fetchContributors$: Observable<Action> = createEffect(() => this.actions$
.pipe(
ofType<FetchAgentContributorsAction>(ActionTypes.FetchAgentContributors),
mergeMap(() => this.http.get<UHKContributor[]>(Constants.AGENT_CONTRIBUTORS_GITHUB_API_URL)),
Expand All @@ -59,7 +60,8 @@ export class ContributorsEffect {
}
),
catchError(error => of(new AgentContributorsNotAvailableAction(error)))
);
)
);

constructor(private store: Store<AppState>, private actions$: Actions, private http: HttpClient) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { ROUTER_NAVIGATED } from '@ngrx/router-store';
import { distinctUntilChanged, filter, map } from 'rxjs/operators';

Expand All @@ -14,21 +14,23 @@ import { RouterState } from '../router-util';

@Injectable()
export class DefaultUserConfigurationEffect {
@Effect() loadDefaultUserConfiguration$ = this.actions$
loadDefaultUserConfiguration$ = createEffect(() => this.actions$
.pipe(
ofType<LoadDefaultUserConfigurationAction>(ActionTypes.LoadDefaultUserConfiguration),
map(() => new LoadDefaultUserConfigurationSuccessAction(this.defaultUserConfigurationService.getDefault()))
);
)
);

@Effect() addKeymapNavigated$ = this.actions$
addKeymapNavigated$ = createEffect(() => this.actions$
.pipe(
ofType<RouterNavigatedAction>(ROUTER_NAVIGATED),
map<RouterNavigatedAction, RouterState>(action => action.payload.routerState as any),
filter(routerState => routerState.url.startsWith('/add-keymap')),
map(routerState => routerState.params.newKeymapAbbr),
distinctUntilChanged(),
map(abbreviation => new AddKeymapSelectedAction(abbreviation))
);
)
);

constructor(private actions$: Actions,
private defaultUserConfigurationService: DefaultUserConfigurationService) {
Expand Down
Loading