From 47a03a08228ed0cf49fc8ff9f2170d7a6fd57591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiss=20R=C3=B3bert?= Date: Sat, 7 Oct 2023 22:20:38 +0200 Subject: [PATCH] chore: use createEffect instead of deprecated Effect --- .../effects/advanced-settings.effects.ts | 8 +- .../src/app/store/effects/app-update.ts | 35 +++-- packages/uhk-web/src/app/store/effects/app.ts | 53 ++++--- .../app/store/effects/auto-update-settings.ts | 7 +- .../app/store/effects/contributors.effect.ts | 12 +- .../default-user-configuration.effect.ts | 12 +- .../uhk-web/src/app/store/effects/device.ts | 132 +++++++++++------- .../uhk-web/src/app/store/effects/keymap.ts | 20 ++- .../uhk-web/src/app/store/effects/macro.ts | 14 +- .../store/effects/smart-macro-doc.effect.ts | 14 +- .../src/app/store/effects/user-config.ts | 67 +++++---- .../user-configuration-history.effects.ts | 14 +- 12 files changed, 241 insertions(+), 147 deletions(-) diff --git a/packages/uhk-web/src/app/store/effects/advanced-settings.effects.ts b/packages/uhk-web/src/app/store/effects/advanced-settings.effects.ts index 92952b62879..d82d1bee584 100644 --- a/packages/uhk-web/src/app/store/effects/advanced-settings.effects.ts +++ b/packages/uhk-web/src/app/store/effects/advanced-settings.effects.ts @@ -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'; @@ -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, diff --git a/packages/uhk-web/src/app/store/effects/app-update.ts b/packages/uhk-web/src/app/store/effects/app-update.ts index 0e4ee805070..cb62e2ea4d8 100644 --- a/packages/uhk-web/src/app/store/effects/app-update.ts +++ b/packages/uhk-web/src/app/store/effects/app-update.ts @@ -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'; @@ -20,16 +20,18 @@ import { AppState, isForceUpdate } from '../index'; @Injectable() export class AppUpdateEffect { - @Effect({ dispatch: false }) appStart$: Observable = 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(AutoUpdateActionTypes.CheckForUpdateNow), map(action => action.payload), @@ -37,18 +39,22 @@ export class AppUpdateEffect { this.logService.misc('[AppUpdateEffect] call checkForUpdate'); this.appUpdateRendererService.checkForUpdate(allowPrerelease); }) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) forceUpdate$ = this.actions$ + forceUpdate$ = createEffect(() => this.actions$ .pipe( ofType(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(ActionTypes.UpdateAvailable), withLatestFrom(this.store.select(isForceUpdate)), @@ -59,9 +65,11 @@ export class AppUpdateEffect { return EMPTY; }) - ); + ), + { dispatch: false } + ); - @Effect() handleError$: Observable = this.actions$ + handleError$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.UpdateError), map(action => action.payload), @@ -71,7 +79,8 @@ export class AppUpdateEffect { message }); }) - ); + ) + ); constructor(private actions$: Actions, private appUpdateRendererService: AppUpdateRendererService, diff --git a/packages/uhk-web/src/app/store/effects/app.ts b/packages/uhk-web/src/app/store/effects/app.ts index 61c6cd192f3..54f0d002621 100644 --- a/packages/uhk-web/src/app/store/effects/app.ts +++ b/packages/uhk-web/src/app/store/effects/app.ts @@ -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'; @@ -41,7 +40,7 @@ import { DataStorageRepositoryService } from '../../services/datastorage-reposit @Injectable() export class ApplicationEffects { - @Effect() appStart$: Observable = this.actions$ + appStart$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.AppBootstrapped), startWith(new AppStartedAction()), @@ -67,17 +66,20 @@ export class ApplicationEffects { }) ) ) - ); + ) + ); - @Effect({ dispatch: false }) appStartInfo$: Observable = this.actions$ + appStartInfo$= createEffect(() => this.actions$ .pipe( ofType(ActionTypes.LoadAppStartInfo), tap(() => { this.appRendererService.getAppStartInfo(); }) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) showNotification$: Observable = this.actions$ + showNotification$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.AppShowNotification), map(action => action.payload), @@ -87,9 +89,11 @@ export class ApplicationEffects { } this.notifierService.notify(notification.type, notification.message); }) - ); + ), + { dispatch: false } + ); - @Effect() processStartInfo$: Observable = this.actions$ + processStartInfo$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.AppProcessStartInfo), map(action => action.payload), @@ -101,21 +105,23 @@ export class ApplicationEffects { new StartConnectionPollerAction() ]; }) - ); + ) + ); - @Effect() undoLastNotification$: Observable = this.actions$ + undoLastNotification$ = createEffect(() => this.actions$ .pipe( ofType(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(ActionTypes.OpenUrlInNewWindow), withLatestFrom(this.store.select(runningInElectron)), @@ -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, @@ -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(ActionTypes.SetAppTheme), map(action => action.payload), @@ -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(ActionTypes.NavigateTo), map(action => action.payload), @@ -171,7 +182,9 @@ export class ApplicationEffects { this.router.navigate(payload.commands, payload.extras); }, 10); }) - ); + ), + { dispatch: false } + ); constructor(private actions$: Actions, private notifierService: NotifierService, diff --git a/packages/uhk-web/src/app/store/effects/auto-update-settings.ts b/packages/uhk-web/src/app/store/effects/auto-update-settings.ts index ffabbf97088..b5c80c23ca7 100644 --- a/packages/uhk-web/src/app/store/effects/auto-update-settings.ts +++ b/packages/uhk-web/src/app/store/effects/auto-update-settings.ts @@ -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'; @@ -17,7 +17,7 @@ import { ShowNotificationAction } from '../actions/app'; @Injectable() export class AutoUpdateSettingsEffects { - @Effect() sendNotification$: Observable = this.actions$ + sendNotification$: Observable = createEffect(() => this.actions$ .pipe( ofType( ActionTypes.CheckForUpdateFailed, ActionTypes.CheckForUpdateSuccess), @@ -28,7 +28,8 @@ export class AutoUpdateSettingsEffects { message }); }) - ); + ) + ); constructor(private actions$: Actions) { } diff --git a/packages/uhk-web/src/app/store/effects/contributors.effect.ts b/packages/uhk-web/src/app/store/effects/contributors.effect.ts index d3a4022e754..d5941f481f2 100644 --- a/packages/uhk-web/src/app/store/effects/contributors.effect.ts +++ b/packages/uhk-web/src/app/store/effects/contributors.effect.ts @@ -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'; @@ -20,7 +20,7 @@ import { @Injectable() export class ContributorsEffect { - @Effect() getContributors$: Observable = this.actions$ + getContributors$: Observable = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.GetAgentContributors), withLatestFrom(this.store.select(contributors)), @@ -30,9 +30,10 @@ export class ContributorsEffect { } return new AgentContributorsAvailableAction(state.contributors); }) - ); + ) + ); - @Effect() fetchContributors$: Observable = this.actions$ + fetchContributors$: Observable = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.FetchAgentContributors), mergeMap(() => this.http.get(Constants.AGENT_CONTRIBUTORS_GITHUB_API_URL)), @@ -59,7 +60,8 @@ export class ContributorsEffect { } ), catchError(error => of(new AgentContributorsNotAvailableAction(error))) - ); + ) + ); constructor(private store: Store, private actions$: Actions, private http: HttpClient) { } diff --git a/packages/uhk-web/src/app/store/effects/default-user-configuration.effect.ts b/packages/uhk-web/src/app/store/effects/default-user-configuration.effect.ts index 7aba37d283f..5c12d8edfe9 100644 --- a/packages/uhk-web/src/app/store/effects/default-user-configuration.effect.ts +++ b/packages/uhk-web/src/app/store/effects/default-user-configuration.effect.ts @@ -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'; @@ -14,13 +14,14 @@ import { RouterState } from '../router-util'; @Injectable() export class DefaultUserConfigurationEffect { - @Effect() loadDefaultUserConfiguration$ = this.actions$ + loadDefaultUserConfiguration$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.LoadDefaultUserConfiguration), map(() => new LoadDefaultUserConfigurationSuccessAction(this.defaultUserConfigurationService.getDefault())) - ); + ) + ); - @Effect() addKeymapNavigated$ = this.actions$ + addKeymapNavigated$ = createEffect(() => this.actions$ .pipe( ofType(ROUTER_NAVIGATED), map(action => action.payload.routerState as any), @@ -28,7 +29,8 @@ export class DefaultUserConfigurationEffect { map(routerState => routerState.params.newKeymapAbbr), distinctUntilChanged(), map(abbreviation => new AddKeymapSelectedAction(abbreviation)) - ); + ) + ); constructor(private actions$: Actions, private defaultUserConfigurationService: DefaultUserConfigurationService) { diff --git a/packages/uhk-web/src/app/store/effects/device.ts b/packages/uhk-web/src/app/store/effects/device.ts index 10db296f13c..f13f95d6d86 100644 --- a/packages/uhk-web/src/app/store/effects/device.ts +++ b/packages/uhk-web/src/app/store/effects/device.ts @@ -1,9 +1,9 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; -import { Actions, Effect, ofType } from '@ngrx/effects'; +import { Actions, createEffect, ofType } from '@ngrx/effects'; import { ROUTER_NAVIGATED, RouterNavigatedAction } from '@ngrx/router-store'; import { Action, Store } from '@ngrx/store'; -import { EMPTY, Observable, of, timer } from 'rxjs'; +import { EMPTY, of, timer } from 'rxjs'; import { distinctUntilChanged, map, mergeMap, pairwise, switchMap, tap, withLatestFrom } from 'rxjs/operators'; import { @@ -75,16 +75,18 @@ import { getVersions } from '../../util'; export class DeviceEffects { private shouldUpgradeAgent = false; - @Effect({dispatch:false}) changeKeyboardLayout$ = this.actions$ + changeKeyboardLayout$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.ChangeKeyboardLayout), withLatestFrom(this.store.select(getDeviceId)), tap(([action, deviceId]) => { this.deviceRendererService.changeKeyboardLayout(action.layout, deviceId); }) - ); + ), + {dispatch:false} + ); - @Effect() changeKeyboardLayoutFailed$ = this.actions$ + changeKeyboardLayoutFailed$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.ChangeKeyboardLayoutReply), map(action => { @@ -97,9 +99,10 @@ export class DeviceEffects { type: NotificationType.Error, }); }) - ); + ) + ); - @Effect() deviceConnectionStateChange$: Observable = this.actions$ + deviceConnectionStateChange$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.ConnectionStateChanged), withLatestFrom( @@ -180,17 +183,20 @@ export class DeviceEffects { return EMPTY; }) - ); + ) + ); - @Effect({ dispatch: false }) setPrivilegeOnLinux$: Observable = this.actions$ + setPrivilegeOnLinux$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SetPrivilegeOnLinux), tap(() => { this.deviceRendererService.setPrivilegeOnLinux(); }) - ); + ), + { dispatch: false } + ); - @Effect() setPrivilegeOnLinuxReply$: Observable = this.actions$ + setPrivilegeOnLinuxReply$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SetPrivilegeOnLinuxReply), map(action => action.payload), @@ -202,9 +208,10 @@ export class DeviceEffects { return of(new SetupPermissionErrorAction(response.error)); }) - ); + ) + ); - @Effect({ dispatch: false }) saveConfiguration$: Observable = this.actions$ + saveConfiguration$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SaveConfiguration), withLatestFrom(this.store, this.store.select(getShowFirmwareUpgradePanel)), @@ -219,9 +226,11 @@ export class DeviceEffects { 100); }), switchMap(() => EMPTY) - ); + ), + { dispatch: false } + ); - @Effect() saveConfigurationReply$: Observable = this.actions$ + saveConfigurationReply$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SaveConfigurationReply), map(action => action.payload), @@ -240,9 +249,10 @@ export class DeviceEffects { new SaveToKeyboardSuccessFailed() ]; }) - ); + ) + ); - @Effect() autoHideSaveToKeyboardButton$: Observable = this.actions$ + autoHideSaveToKeyboardButton$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SaveToKeyboardSuccess), withLatestFrom(this.store), @@ -260,9 +270,10 @@ export class DeviceEffects { }) ) ) - ); + ) + ); - @Effect() resetMouseSpeedSettings$: Observable = this.actions$ + resetMouseSpeedSettings$ = createEffect(() => this.actions$ .pipe( ofType( ActionTypes.ResetPcMouseSpeedSettings, @@ -270,9 +281,10 @@ export class DeviceEffects { ), withLatestFrom(this.store.select(getUserConfiguration)), map(([action, config]) => new LoadResetUserConfigurationAction(config)) - ); + ) + ); - @Effect() resetUserConfiguration$: Observable = this.actions$ + resetUserConfiguration$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.ResetUserConfiguration), switchMap(() => { @@ -280,9 +292,10 @@ export class DeviceEffects { config.keymaps = config.keymaps.filter(keymap => keymap.abbreviation !== 'EMP'); return of(new LoadResetUserConfigurationAction(config)); }) - ); + ) + ); - @Effect() saveResetUserConfigurationToDevice$ = this.actions$ + saveResetUserConfigurationToDevice$ = createEffect(() => this.actions$ .pipe( ofType(UserConfigActions.LoadResetUserConfiguration), map(action => action.payload), @@ -291,9 +304,10 @@ export class DeviceEffects { map(() => new SaveConfigurationAction(true)) ) ) - ); + ) + ); - @Effect() applyUserConfigurationFromFileAction$ = this.actions$ + applyUserConfigurationFromFileAction$ = createEffect(() => this.actions$ .pipe( ofType(UserConfigActions.ApplyUserConfigurationFromFile), map(action => action.payload), @@ -302,9 +316,10 @@ export class DeviceEffects { map(() => new SaveConfigurationAction(payload.saveInHistory)) ) ) - ); + ) + ); - @Effect({ dispatch: false }) updateFirmware$ = this.actions$ + updateFirmware$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.UpdateFirmware), withLatestFrom(this.store.select(getUserConfiguration)), @@ -313,9 +328,11 @@ export class DeviceEffects { forceUpgrade: action.payload, versionInformation: getVersions() })) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) updateFirmwareWith$ = this.actions$ + updateFirmwareWith$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.UpdateFirmwareWith), withLatestFrom(this.store.select(getUserConfiguration)), @@ -325,14 +342,15 @@ export class DeviceEffects { versionInformation: getVersions(), uploadFile: action.payload.uploadFileData })) - ); + ), + { dispatch: false } + ); - @Effect() updateFirmwareReply$ = this.actions$ + updateFirmwareReply$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.UpdateFirmwareReply), map(action => action.payload), - switchMap((response: FirmwareUpgradeIpcResponse) - : Observable => { + switchMap((response: FirmwareUpgradeIpcResponse) => { if (response.success) { return of(new UpdateFirmwareSuccessAction({ @@ -351,22 +369,26 @@ export class DeviceEffects { modules: response.modules })); }) - ); + ) + ); - @Effect() restoreUserConfiguration$ = this.actions$ + restoreUserConfiguration$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.RestoreConfigurationFromBackup), map(() => new SaveConfigurationAction(true)) - ); + ) + ); - @Effect({ dispatch: false }) recoveryDevice$ = this.actions$ + recoveryDevice$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.RecoveryDevice), withLatestFrom(this.store.select(getUserConfiguration)), tap(([, userConfig]) => this.deviceRendererService.recoveryDevice(userConfig)) - ); + ), + { dispatch: false } + ); - @Effect() recoveryDeviceReply$ = this.actions$ + recoveryDeviceReply$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.RecoveryDeviceReply), map(action => action.payload), @@ -390,34 +412,43 @@ export class DeviceEffects { }) ]; }) - ); + ) + ); - @Effect({ dispatch: false }) recoveryModule$ = this.actions$ + recoveryModule$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.RecoveryModule), map(action => action.payload), tap(moduleId => this.deviceRendererService.recoveryModule(moduleId)) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) enableUsbStackTest$ = this.actions$ + enableUsbStackTest$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.EnableUsbStackTest), tap(() => this.deviceRendererService.enableUsbStackTest()) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) startConnectionPoller$ = this.actions$ + startConnectionPoller$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.StartConnectionPoller), tap(() => this.deviceRendererService.startConnectionPoller()) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) readConfigSizes$ = this.actions$ + readConfigSizes$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.ReadConfigSizes), tap(() => this.deviceRendererService.readConfigSizes()) - ); + ), + { dispatch: false } + ); - @Effect() skipFirmwareUpgrade$: Observable = this.actions$ + skipFirmwareUpgrade$ = createEffect(() => this.actions$ .pipe( ofType(ROUTER_NAVIGATED), map(action => action?.payload?.routerState?.url), @@ -428,7 +459,8 @@ export class DeviceEffects { return new EmptyAction(); }) - ); + ) + ); constructor(private actions$: Actions, private router: Router, diff --git a/packages/uhk-web/src/app/store/effects/keymap.ts b/packages/uhk-web/src/app/store/effects/keymap.ts index 465a093b2f6..8a25a44c1da 100644 --- a/packages/uhk-web/src/app/store/effects/keymap.ts +++ b/packages/uhk-web/src/app/store/effects/keymap.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; -import { Actions, Effect, ofType } from '@ngrx/effects'; +import { Actions, createEffect, ofType } from '@ngrx/effects'; import { Store } from '@ngrx/store'; import { map, pairwise, tap, withLatestFrom } from 'rxjs/operators'; @@ -13,7 +13,7 @@ import { AppState, getKeymaps } from '../index'; @Injectable() export class KeymapEffects { - @Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$ + addOrDuplicate$ = createEffect(() => this.actions$ .pipe( ofType(Keymaps.ActionTypes.Add, Keymaps.ActionTypes.Duplicate), withLatestFrom(this.store.select(getKeymaps) @@ -26,9 +26,11 @@ export class KeymapEffects { const newKeymap = findNewItem(prevKeymaps, newKeymaps); this.router.navigate(['/keymap', newKeymap.abbreviation]); }) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) remove$: any = this.actions$ + remove$ = createEffect(() => this.actions$ .pipe( ofType(Keymaps.ActionTypes.Remove), withLatestFrom(this.store.select(getKeymaps)), @@ -41,9 +43,11 @@ export class KeymapEffects { this.router.navigate(['/keymap', favourite.abbreviation]); } }) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) editAbbr$: any = this.actions$ + editAbbr$ = createEffect(() => this.actions$ .pipe( ofType(Keymaps.ActionTypes.EditAbbr), withLatestFrom(this.store.select(getKeymaps)), @@ -55,7 +59,9 @@ export class KeymapEffects { } } }) - ); + ), + { dispatch: false } + ); constructor(private actions$: Actions, private router: Router, private store: Store) { } diff --git a/packages/uhk-web/src/app/store/effects/macro.ts b/packages/uhk-web/src/app/store/effects/macro.ts index df8732d00a0..65df9bab912 100644 --- a/packages/uhk-web/src/app/store/effects/macro.ts +++ b/packages/uhk-web/src/app/store/effects/macro.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; -import { Actions, createEffect, Effect, ofType } from '@ngrx/effects'; +import { Actions, createEffect, ofType } from '@ngrx/effects'; import { Store } from '@ngrx/store'; import { routerNavigatedAction } from '@ngrx/router-store'; import { distinctUntilChanged, map, tap, withLatestFrom } from 'rxjs/operators'; @@ -23,7 +23,7 @@ export class MacroEffects { map(macroId => new SelectMacroAction(+macroId)) )); - @Effect({ dispatch: false }) remove$: any = this.actions$ + remove$ = createEffect(() => this.actions$ .pipe( ofType(Macros.ActionTypes.Remove), tap(action => this.store.dispatch(new Keymaps.CheckMacroAction(action.payload))), @@ -31,16 +31,20 @@ export class MacroEffects { map(([, newMacro]) => newMacro), tap(this.navigateToNewMacro.bind(this)) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$ + addOrDuplicate$ = createEffect(() => this.actions$ .pipe( ofType( Macros.ActionTypes.Add, Macros.ActionTypes.Duplicate), withLatestFrom(this.store.select(getSelectedMacro)), map(([, newMacro]) => newMacro), tap(this.navigateToNewMacro.bind(this)) - ); + ), + { dispatch: false } + ); private navigateToNewMacro(newMacro: Macro): Promise { if (newMacro) { diff --git a/packages/uhk-web/src/app/store/effects/smart-macro-doc.effect.ts b/packages/uhk-web/src/app/store/effects/smart-macro-doc.effect.ts index fdaeab8c34e..dcef1a9c3e0 100644 --- a/packages/uhk-web/src/app/store/effects/smart-macro-doc.effect.ts +++ b/packages/uhk-web/src/app/store/effects/smart-macro-doc.effect.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { Store } from '@ngrx/store'; -import { Actions, Effect, ofType } from '@ngrx/effects'; +import { Actions, createEffect, ofType } from '@ngrx/effects'; import { tap, withLatestFrom } from 'rxjs/operators'; import { FirmwareRepoInfo } from 'uhk-common'; @@ -13,20 +13,24 @@ import { AppState, getRightModuleFirmwareRepoInfo, getSmartMacroDocModuleIds } f @Injectable() export class SmartMacroDocEffect { - @Effect({ dispatch: false }) smartMacroTogglePanelVisibility$ = this.actions$ + smartMacroTogglePanelVisibility$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.TogglePanelVisibility), withLatestFrom(this.store.select(getRightModuleFirmwareRepoInfo)), tap(([, firmwareRepoInfo]) => this.smartMacroDocRendererService.downloadDocumentation(firmwareRepoInfo)) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) smartMacroDocInited$ = this.actions$ + smartMacroDocInited$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SmdInited, Device.ActionTypes.ModulesInfoLoaded, Device.ActionTypes.ConnectionStateChanged, Device.ActionTypes.UpdateFirmwareSuccess, Device.ActionTypes.UpdateFirmwareFailed), withLatestFrom(this.store.select(getSmartMacroDocModuleIds), this.store.select(getRightModuleFirmwareRepoInfo)), tap(([, modules, repoInfo]) => this.sendMessageContext(modules, repoInfo)) - ); + ), + { dispatch: false } + ); constructor(private actions$: Actions, private smartMacroDocRendererService: SmartMacroDocRendererService, diff --git a/packages/uhk-web/src/app/store/effects/user-config.ts b/packages/uhk-web/src/app/store/effects/user-config.ts index b5d83c8e1e9..2f51451b0bb 100644 --- a/packages/uhk-web/src/app/store/effects/user-config.ts +++ b/packages/uhk-web/src/app/store/effects/user-config.ts @@ -1,9 +1,9 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; -import { Actions, Effect, ofType } from '@ngrx/effects'; -import { defer, Observable } from 'rxjs'; +import { Actions, createEffect, ofType, ROOT_EFFECTS_INIT } from '@ngrx/effects'; +import { Observable } from 'rxjs'; import { map, mergeMap, switchMap, tap, withLatestFrom } from 'rxjs/operators'; -import { Action, Store } from '@ngrx/store'; +import { Store } from '@ngrx/store'; import { saveAs } from 'file-saver'; import { Buffer } from 'uhk-common'; @@ -53,14 +53,18 @@ import { LoadUserConfigurationFromFilePayload } from '../../models'; @Injectable() export class UserConfigEffects { - @Effect() loadUserConfig$: Observable = defer(() => { - return this.getUserConfiguration() - .pipe( - map(userConfig => new LoadUserConfigSuccessAction(userConfig)) - ); - }); + loadUserConfig$ = createEffect(() => this.actions$ + .pipe( + ofType(ROOT_EFFECTS_INIT), + switchMap(() => this.getUserConfiguration() + .pipe( + map(userConfig => new LoadUserConfigSuccessAction(userConfig)) + ) + ) + ) + ); - @Effect() saveUserConfig$: Observable = this.actions$ + saveUserConfig$ = createEffect(() => this.actions$ .pipe( ofType( Keymaps.ActionTypes.Add, Keymaps.ActionTypes.Duplicate, Keymaps.ActionTypes.EditName, @@ -111,9 +115,10 @@ export class UserConfigEffects { }) ); }) - ); + ) + ); - @Effect() undoUserConfig$: Observable = this.actions$ + undoUserConfig$ = createEffect(() => this.actions$ .pipe( ofType(Keymaps.ActionTypes.UndoLastAction), map(action => action.payload), @@ -123,19 +128,22 @@ export class UserConfigEffects { map(() => new LoadUserConfigSuccessAction(payload.config)) ) ) - ); + ) + ); - @Effect({ dispatch: false }) loadConfigFromDevice$ = this.actions$ + loadConfigFromDevice$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.LoadConfigFromDevice), tap(() => this.deviceRendererService.loadConfigurationFromKeyboard(getVersions())) - ); + ), + { dispatch: false } + ); - @Effect() loadConfigFromDeviceReply$ = this.actions$ + loadConfigFromDeviceReply$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.LoadConfigFromDeviceReply), withLatestFrom(this.store.select(getRouterState)), - mergeMap(([action, route]): any => { + mergeMap(([action, route]) => { const data: ConfigurationReply = action.payload; if (!data.success) { @@ -191,9 +199,10 @@ export class UserConfigEffects { return result; }) - ); + ) + ); - @Effect({ dispatch: false }) saveUserConfigInJsonFile$ = this.actions$ + saveUserConfigInJsonFile$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SaveUserConfigInJsonFile), withLatestFrom(this.store.select(getUserConfiguration)), @@ -202,9 +211,11 @@ export class UserConfigEffects { const asBlob = new Blob([asString], { type: 'text/plain' }); saveAs(asBlob, 'UserConfiguration.json'); }) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) saveUserConfigInBinFile$ = this.actions$ + saveUserConfigInBinFile$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.SaveUserConfigInBinFile), withLatestFrom(this.store.select(getUserConfiguration)), @@ -214,9 +225,11 @@ export class UserConfigEffects { const blob = new Blob([uhkBuffer.getBufferContent()]); saveAs(blob, 'UserConfiguration.bin'); }) - ); + ), + { dispatch: false } + ); - @Effect() loadUserConfigurationFromFile$ = this.actions$ + loadUserConfigurationFromFile$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.LoadUserConfigurationFromFile), map(action => action.payload), @@ -254,13 +267,15 @@ export class UserConfigEffects { }); } }) - ); + ) + ); - @Effect() previewUserConfiguration$ = this.actions$ + previewUserConfiguration$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.PreviewUserConfiguration), map(() => new ShowSaveToKeyboardButtonAction()) - ); + ) + ); constructor(private actions$: Actions, private dataStorageRepository: DataStorageRepositoryService, diff --git a/packages/uhk-web/src/app/store/effects/user-configuration-history.effects.ts b/packages/uhk-web/src/app/store/effects/user-configuration-history.effects.ts index 6e45532e22f..529a8de5aaa 100644 --- a/packages/uhk-web/src/app/store/effects/user-configuration-history.effects.ts +++ b/packages/uhk-web/src/app/store/effects/user-configuration-history.effects.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { Actions, Effect, ofType } from '@ngrx/effects'; +import { Actions, createEffect, ofType } from '@ngrx/effects'; import { tap, map } from 'rxjs/operators'; import { DeviceRendererService } from '../../services/device-renderer.service'; @@ -7,22 +7,26 @@ import { ActionTypes, GetUserConfigurationFromHistoryAction } from '../actions/u @Injectable() export class UserConfigurationHistoryEffects { - @Effect({ dispatch: false }) loadUserConfigHistory$ = this.actions$ + loadUserConfigHistory$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.LoadUserConfigurationHistory), tap(() => { this.deviceRendererService.loadUserConfigurationHistory(); }) - ); + ), + { dispatch: false } + ); - @Effect({ dispatch: false }) getUserConfigFromHistory$ = this.actions$ + getUserConfigFromHistory$ = createEffect(() => this.actions$ .pipe( ofType(ActionTypes.GetUserConfigurationFromHistory), map(action => action.payload), tap((fileName: string) => { this.deviceRendererService.getUserConfigurationFromHistory(fileName); }) - ); + ), + { dispatch: false } + ); constructor(private actions$: Actions, private deviceRendererService: DeviceRendererService