From 4b310dd1e73d7335483e919d8ac909bf2638a8f9 Mon Sep 17 00:00:00 2001 From: Jovan Mitrovic <79802504+jovanmit998@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:22:55 +0100 Subject: [PATCH] refactor(example-app): use create action group function for actions (#4239) --- .../src/app/auth/actions/auth-api.actions.ts | 21 +++---- .../src/app/auth/actions/auth.actions.ts | 15 +++-- .../example-app/src/app/auth/actions/index.ts | 5 -- .../app/auth/actions/login-page.actions.ts | 12 ++-- .../containers/login-page.component.spec.ts | 2 +- .../auth/containers/login-page.component.ts | 2 +- .../src/app/auth/effects/auth.effects.spec.ts | 8 +-- .../src/app/auth/effects/auth.effects.ts | 10 ++-- .../app/auth/reducers/auth.reducer.spec.ts | 3 +- .../src/app/auth/reducers/auth.reducer.ts | 3 +- .../auth/reducers/login-page.reducer.spec.ts | 3 +- .../app/auth/reducers/login-page.reducer.ts | 3 +- .../app/auth/services/auth-guard.service.ts | 2 +- .../src/app/books/actions/book.actions.ts | 12 ++-- .../app/books/actions/books-api.actions.ts | 18 +++--- .../books/actions/collection-api.actions.ts | 58 +++++++------------ .../books/actions/collection-page.actions.ts | 15 +++-- .../books/actions/find-book-page.actions.ts | 12 ++-- .../src/app/books/actions/index.ts | 17 ------ .../actions/selected-book-page.actions.ts | 29 +++++----- .../books/actions/view-book-page.actions.ts | 12 ++-- .../collection-page.component.spec.ts | 2 +- .../containers/collection-page.component.ts | 2 +- .../find-book-page.component.spec.ts | 2 +- .../containers/find-book-page.component.ts | 2 +- .../selected-book-page.component.spec.ts | 2 +- .../selected-book-page.component.ts | 2 +- .../view-book-page.component.spec.ts | 2 +- .../containers/view-book-page.component.ts | 2 +- .../app/books/effects/book.effects.spec.ts | 6 +- .../src/app/books/effects/book.effects.ts | 6 +- .../books/effects/collection.effects.spec.ts | 8 +-- .../app/books/effects/collection.effects.ts | 8 +-- .../src/app/books/guards/book-exists.guard.ts | 2 +- .../app/books/reducers/books.reducer.spec.ts | 10 ++-- .../src/app/books/reducers/books.reducer.ts | 10 ++-- .../app/books/reducers/collection.reducer.ts | 8 +-- .../src/app/books/reducers/search.reducer.ts | 6 +- .../example-app/src/app/core/actions/index.ts | 4 -- .../src/app/core/actions/layout.actions.ts | 11 +++- .../src/app/core/actions/user.actions.ts | 9 ++- .../src/app/core/containers/app.component.ts | 4 +- .../src/app/core/effects/user.effects.spec.ts | 2 +- .../src/app/core/effects/user.effects.ts | 2 +- .../src/app/core/reducers/layout.reducer.ts | 4 +- 45 files changed, 170 insertions(+), 208 deletions(-) delete mode 100644 projects/example-app/src/app/auth/actions/index.ts delete mode 100644 projects/example-app/src/app/books/actions/index.ts delete mode 100644 projects/example-app/src/app/core/actions/index.ts diff --git a/projects/example-app/src/app/auth/actions/auth-api.actions.ts b/projects/example-app/src/app/auth/actions/auth-api.actions.ts index 6d61b97db8..1d7c54a2df 100644 --- a/projects/example-app/src/app/auth/actions/auth-api.actions.ts +++ b/projects/example-app/src/app/auth/actions/auth-api.actions.ts @@ -1,14 +1,11 @@ -import { props, createAction } from '@ngrx/store'; +import { props, createActionGroup, emptyProps } from '@ngrx/store'; import { User } from '@example-app/auth/models'; -export const loginSuccess = createAction( - '[Auth/API] Login Success', - props<{ user: User }>() -); - -export const loginFailure = createAction( - '[Auth/API] Login Failure', - props<{ error: any }>() -); - -export const loginRedirect = createAction('[Auth/API] Login Redirect'); +export const AuthApiActions = createActionGroup({ + source: 'Auth/API', + events: { + 'Login Success': props<{ user: User }>(), + 'Login Failure': props<{ error: any }>(), + 'Login Redirect': emptyProps(), + }, +}); diff --git a/projects/example-app/src/app/auth/actions/auth.actions.ts b/projects/example-app/src/app/auth/actions/auth.actions.ts index 2c04b8932a..ee7a656b79 100644 --- a/projects/example-app/src/app/auth/actions/auth.actions.ts +++ b/projects/example-app/src/app/auth/actions/auth.actions.ts @@ -1,7 +1,10 @@ -import { createAction } from '@ngrx/store'; +import { createActionGroup, emptyProps } from '@ngrx/store'; -export const logout = createAction('[Auth] Logout'); -export const logoutConfirmation = createAction('[Auth] Logout Confirmation'); -export const logoutConfirmationDismiss = createAction( - '[Auth] Logout Confirmation Dismiss' -); +export const AuthActions = createActionGroup({ + source: 'Auth', + events: { + Logout: emptyProps(), + 'Logout Confirmation': emptyProps(), + 'Logout Confirmation Dismiss': emptyProps(), + }, +}); diff --git a/projects/example-app/src/app/auth/actions/index.ts b/projects/example-app/src/app/auth/actions/index.ts deleted file mode 100644 index f7e4df41be..0000000000 --- a/projects/example-app/src/app/auth/actions/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as AuthActions from './auth.actions'; -import * as AuthApiActions from './auth-api.actions'; -import * as LoginPageActions from './login-page.actions'; - -export { AuthActions, AuthApiActions, LoginPageActions }; diff --git a/projects/example-app/src/app/auth/actions/login-page.actions.ts b/projects/example-app/src/app/auth/actions/login-page.actions.ts index af315f1cc6..cad898fcae 100644 --- a/projects/example-app/src/app/auth/actions/login-page.actions.ts +++ b/projects/example-app/src/app/auth/actions/login-page.actions.ts @@ -1,7 +1,9 @@ -import { createAction, props } from '@ngrx/store'; +import { createActionGroup, props } from '@ngrx/store'; import { Credentials } from '@example-app/auth/models'; -export const login = createAction( - '[Login Page] Login', - props<{ credentials: Credentials }>() -); +export const LoginPageActions = createActionGroup({ + source: 'Login Page', + events: { + Login: props<{ credentials: Credentials }>(), + }, +}); diff --git a/projects/example-app/src/app/auth/containers/login-page.component.spec.ts b/projects/example-app/src/app/auth/containers/login-page.component.spec.ts index ce5eaef0da..b9433c4573 100644 --- a/projects/example-app/src/app/auth/containers/login-page.component.spec.ts +++ b/projects/example-app/src/app/auth/containers/login-page.component.spec.ts @@ -4,7 +4,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { LoginPageComponent } from '@example-app/auth/containers'; import { LoginFormComponent } from '@example-app/auth/components'; import * as fromAuth from '@example-app/auth/reducers'; -import { LoginPageActions } from '@example-app/auth/actions'; +import { LoginPageActions } from '@example-app/auth/actions/login-page.actions'; import { provideMockStore, MockStore } from '@ngrx/store/testing'; import { MaterialModule } from '@example-app/material'; diff --git a/projects/example-app/src/app/auth/containers/login-page.component.ts b/projects/example-app/src/app/auth/containers/login-page.component.ts index 3d76b23df1..d5dec368ee 100644 --- a/projects/example-app/src/app/auth/containers/login-page.component.ts +++ b/projects/example-app/src/app/auth/containers/login-page.component.ts @@ -2,7 +2,7 @@ import { Component } from '@angular/core'; import { Store } from '@ngrx/store'; import { Credentials } from '@example-app/auth/models'; import * as fromAuth from '@example-app/auth/reducers'; -import { LoginPageActions } from '@example-app/auth/actions'; +import { LoginPageActions } from '@example-app/auth/actions/login-page.actions'; @Component({ selector: 'bc-login-page', diff --git a/projects/example-app/src/app/auth/effects/auth.effects.spec.ts b/projects/example-app/src/app/auth/effects/auth.effects.spec.ts index 570a2c20b3..4540293513 100644 --- a/projects/example-app/src/app/auth/effects/auth.effects.spec.ts +++ b/projects/example-app/src/app/auth/effects/auth.effects.spec.ts @@ -5,11 +5,9 @@ import { Actions } from '@ngrx/effects'; import { provideMockActions } from '@ngrx/effects/testing'; import { cold, hot } from 'jasmine-marbles'; import { Observable, of } from 'rxjs'; -import { - LoginPageActions, - AuthActions, - AuthApiActions, -} from '@example-app/auth/actions'; +import { LoginPageActions } from '@example-app/auth/actions/login-page.actions'; +import { AuthApiActions } from '@example-app/auth/actions/auth-api.actions'; +import { AuthActions } from '@example-app/auth/actions/auth.actions'; import { Credentials, User } from '@example-app/auth/models'; import { AuthService } from '@example-app/auth/services'; diff --git a/projects/example-app/src/app/auth/effects/auth.effects.ts b/projects/example-app/src/app/auth/effects/auth.effects.ts index 114e9cf797..8fe1278272 100644 --- a/projects/example-app/src/app/auth/effects/auth.effects.ts +++ b/projects/example-app/src/app/auth/effects/auth.effects.ts @@ -4,15 +4,13 @@ import { Router } from '@angular/router'; import { Actions, ofType, createEffect } from '@ngrx/effects'; import { of } from 'rxjs'; import { catchError, exhaustMap, map, tap } from 'rxjs/operators'; -import { - LoginPageActions, - AuthActions, - AuthApiActions, -} from '@example-app/auth/actions'; +import { LoginPageActions } from '@example-app/auth/actions/login-page.actions'; +import { AuthApiActions } from '@example-app/auth/actions/auth-api.actions'; +import { AuthActions } from '@example-app/auth/actions/auth.actions'; import { Credentials } from '@example-app/auth/models'; import { AuthService } from '@example-app/auth/services'; import { LogoutConfirmationDialogComponent } from '@example-app/auth/components'; -import { UserActions } from '@example-app/core/actions'; +import { UserActions } from '@example-app/core/actions/user.actions'; @Injectable() export class AuthEffects { diff --git a/projects/example-app/src/app/auth/reducers/auth.reducer.spec.ts b/projects/example-app/src/app/auth/reducers/auth.reducer.spec.ts index 140dac4813..4aa7653c12 100644 --- a/projects/example-app/src/app/auth/reducers/auth.reducer.spec.ts +++ b/projects/example-app/src/app/auth/reducers/auth.reducer.spec.ts @@ -1,6 +1,7 @@ import { reducer } from '@example-app/auth/reducers/auth.reducer'; import * as fromAuth from '@example-app/auth/reducers/auth.reducer'; -import { AuthApiActions, AuthActions } from '@example-app/auth/actions'; +import { AuthApiActions } from '@example-app/auth/actions/auth-api.actions'; +import { AuthActions } from '@example-app/auth/actions/auth.actions'; import { User } from '@example-app/auth/models'; diff --git a/projects/example-app/src/app/auth/reducers/auth.reducer.ts b/projects/example-app/src/app/auth/reducers/auth.reducer.ts index b7cc394e9b..19e3238e6d 100644 --- a/projects/example-app/src/app/auth/reducers/auth.reducer.ts +++ b/projects/example-app/src/app/auth/reducers/auth.reducer.ts @@ -1,5 +1,6 @@ import { createReducer, on } from '@ngrx/store'; -import { AuthApiActions, AuthActions } from '@example-app/auth/actions'; +import { AuthApiActions } from '@example-app/auth/actions/auth-api.actions'; +import { AuthActions } from '@example-app/auth/actions/auth.actions'; import { User } from '@example-app/auth/models'; export const statusFeatureKey = 'status'; diff --git a/projects/example-app/src/app/auth/reducers/login-page.reducer.spec.ts b/projects/example-app/src/app/auth/reducers/login-page.reducer.spec.ts index ca774f8be2..781008a3f1 100644 --- a/projects/example-app/src/app/auth/reducers/login-page.reducer.spec.ts +++ b/projects/example-app/src/app/auth/reducers/login-page.reducer.spec.ts @@ -1,7 +1,8 @@ import { reducer } from '@example-app/auth/reducers/login-page.reducer'; import * as fromLoginPage from '@example-app/auth/reducers/login-page.reducer'; -import { AuthApiActions, LoginPageActions } from '@example-app/auth/actions'; +import { LoginPageActions } from '@example-app/auth/actions/login-page.actions'; +import { AuthApiActions } from '@example-app/auth/actions/auth-api.actions'; import { Credentials, User } from '@example-app/auth/models'; diff --git a/projects/example-app/src/app/auth/reducers/login-page.reducer.ts b/projects/example-app/src/app/auth/reducers/login-page.reducer.ts index d27810ab30..d844c2052d 100644 --- a/projects/example-app/src/app/auth/reducers/login-page.reducer.ts +++ b/projects/example-app/src/app/auth/reducers/login-page.reducer.ts @@ -1,4 +1,5 @@ -import { AuthApiActions, LoginPageActions } from '@example-app/auth/actions'; +import { AuthApiActions } from '@example-app/auth/actions/auth-api.actions'; +import { LoginPageActions } from '@example-app/auth/actions/login-page.actions'; import { createReducer, on } from '@ngrx/store'; export const loginPageFeatureKey = 'loginPage'; diff --git a/projects/example-app/src/app/auth/services/auth-guard.service.ts b/projects/example-app/src/app/auth/services/auth-guard.service.ts index e21b5a6b36..1815dc3c11 100644 --- a/projects/example-app/src/app/auth/services/auth-guard.service.ts +++ b/projects/example-app/src/app/auth/services/auth-guard.service.ts @@ -2,7 +2,7 @@ import { inject } from '@angular/core'; import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { map, take } from 'rxjs/operators'; -import { AuthApiActions } from '@example-app/auth/actions'; +import { AuthApiActions } from '@example-app/auth/actions/auth-api.actions'; import * as fromAuth from '@example-app/auth/reducers'; export const authGuard = (): Observable => { diff --git a/projects/example-app/src/app/books/actions/book.actions.ts b/projects/example-app/src/app/books/actions/book.actions.ts index 7518ae7ede..204f80bae1 100644 --- a/projects/example-app/src/app/books/actions/book.actions.ts +++ b/projects/example-app/src/app/books/actions/book.actions.ts @@ -1,8 +1,10 @@ -import { createAction, props } from '@ngrx/store'; +import { createActionGroup, props } from '@ngrx/store'; import { Book } from '@example-app/books/models'; -export const loadBook = createAction( - '[Book Exists Guard] Load Book', - props<{ book: Book }>() -); +export const BookActions = createActionGroup({ + source: 'Book Exists Guard', + events: { + 'Load Book': props<{ book: Book }>(), + }, +}); diff --git a/projects/example-app/src/app/books/actions/books-api.actions.ts b/projects/example-app/src/app/books/actions/books-api.actions.ts index 392c9aa466..ff2deed5d1 100644 --- a/projects/example-app/src/app/books/actions/books-api.actions.ts +++ b/projects/example-app/src/app/books/actions/books-api.actions.ts @@ -1,13 +1,11 @@ -import { createAction, props } from '@ngrx/store'; +import { createActionGroup, props } from '@ngrx/store'; import { Book } from '@example-app/books/models'; -export const searchSuccess = createAction( - '[Books/API] Search Success', - props<{ books: Book[] }>() -); - -export const searchFailure = createAction( - '[Books/API] Search Failure', - props<{ errorMsg: string }>() -); +export const BooksApiActions = createActionGroup({ + source: 'Books/API', + events: { + 'Search Success': props<{ books: Book[] }>(), + 'Search Failure': props<{ errorMsg: string }>(), + }, +}); diff --git a/projects/example-app/src/app/books/actions/collection-api.actions.ts b/projects/example-app/src/app/books/actions/collection-api.actions.ts index 17f31a3922..d0500432d6 100644 --- a/projects/example-app/src/app/books/actions/collection-api.actions.ts +++ b/projects/example-app/src/app/books/actions/collection-api.actions.ts @@ -1,42 +1,26 @@ -import { createAction, props } from '@ngrx/store'; +import { createActionGroup, props } from '@ngrx/store'; import { Book } from '@example-app/books/models'; -/** - * Add Book to Collection Actions - */ -export const addBookSuccess = createAction( - '[Collection/API] Add Book Success', - props<{ book: Book }>() -); +export const CollectionApiActions = createActionGroup({ + source: 'Collection/API', + events: { + /** + * Add Book to Collection Actions + */ + 'Add Book Success': props<{ book: Book }>(), + 'Add Book Failure': props<{ book: Book }>(), -export const addBookFailure = createAction( - '[Collection/API] Add Book Failure', - props<{ book: Book }>() -); + /** + * Remove Book from Collection Actions + */ + 'Remove Book Success': props<{ book: Book }>(), + 'Remove Book Failure': props<{ book: Book }>(), -/** - * Remove Book from Collection Actions - */ -export const removeBookSuccess = createAction( - '[Collection/API] Remove Book Success', - props<{ book: Book }>() -); - -export const removeBookFailure = createAction( - '[Collection/API] Remove Book Failure', - props<{ book: Book }>() -); - -/** - * Load Collection Actions - */ -export const loadBooksSuccess = createAction( - '[Collection/API] Load Books Success', - props<{ books: Book[] }>() -); - -export const loadBooksFailure = createAction( - '[Collection/API] Load Books Failure', - props<{ error: any }>() -); + /** + * Load Collection Actions + */ + 'Load Books Success': props<{ books: Book[] }>(), + 'Load Books Failure': props<{ error: any }>(), + }, +}); diff --git a/projects/example-app/src/app/books/actions/collection-page.actions.ts b/projects/example-app/src/app/books/actions/collection-page.actions.ts index bf0367abae..5338d80b5b 100644 --- a/projects/example-app/src/app/books/actions/collection-page.actions.ts +++ b/projects/example-app/src/app/books/actions/collection-page.actions.ts @@ -1,6 +1,11 @@ -import { createAction } from '@ngrx/store'; +import { createActionGroup, emptyProps } from '@ngrx/store'; -/** - * Load Collection Action - */ -export const enter = createAction('[Collection Page] Enter'); +export const CollectionPageActions = createActionGroup({ + source: 'Collection Page', + events: { + /** + * Load Collection Action + */ + Enter: emptyProps(), + }, +}); diff --git a/projects/example-app/src/app/books/actions/find-book-page.actions.ts b/projects/example-app/src/app/books/actions/find-book-page.actions.ts index 31cb0e7f87..8fd10fe4ee 100644 --- a/projects/example-app/src/app/books/actions/find-book-page.actions.ts +++ b/projects/example-app/src/app/books/actions/find-book-page.actions.ts @@ -1,6 +1,8 @@ -import { createAction, props } from '@ngrx/store'; +import { createActionGroup, props } from '@ngrx/store'; -export const searchBooks = createAction( - '[Find Book Page] Search Books', - props<{ query: string }>() -); +export const FindBookPageActions = createActionGroup({ + source: 'Find Book Page', + events: { + 'Search Books': props<{ query: string }>(), + }, +}); diff --git a/projects/example-app/src/app/books/actions/index.ts b/projects/example-app/src/app/books/actions/index.ts deleted file mode 100644 index 39108ed1a2..0000000000 --- a/projects/example-app/src/app/books/actions/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as BookActions from './book.actions'; -import * as BooksApiActions from './books-api.actions'; -import * as CollectionApiActions from './collection-api.actions'; -import * as CollectionPageActions from './collection-page.actions'; -import * as FindBookPageActions from './find-book-page.actions'; -import * as SelectedBookPageActions from './selected-book-page.actions'; -import * as ViewBookPageActions from './view-book-page.actions'; - -export { - BookActions, - BooksApiActions, - CollectionApiActions, - CollectionPageActions, - FindBookPageActions, - SelectedBookPageActions, - ViewBookPageActions, -}; diff --git a/projects/example-app/src/app/books/actions/selected-book-page.actions.ts b/projects/example-app/src/app/books/actions/selected-book-page.actions.ts index 591fdf1b45..f67953c06c 100644 --- a/projects/example-app/src/app/books/actions/selected-book-page.actions.ts +++ b/projects/example-app/src/app/books/actions/selected-book-page.actions.ts @@ -1,19 +1,18 @@ -import { createAction, props } from '@ngrx/store'; +import { createActionGroup, props } from '@ngrx/store'; import { Book } from '@example-app/books/models'; -/** - * Add Book to Collection Action - */ -export const addBook = createAction( - '[Selected Book Page] Add Book', - props<{ book: Book }>() -); +export const SelectedBookPageActions = createActionGroup({ + source: 'Selected Book Page', + events: { + /** + * Add Book to Collection Action + */ + 'Add Book': props<{ book: Book }>(), -/** - * Remove Book from Collection Action - */ -export const removeBook = createAction( - '[Selected Book Page] Remove Book', - props<{ book: Book }>() -); + /** + * Remove Book from Collection Action + */ + 'Remove Book': props<{ book: Book }>(), + }, +}); diff --git a/projects/example-app/src/app/books/actions/view-book-page.actions.ts b/projects/example-app/src/app/books/actions/view-book-page.actions.ts index cfa9787a31..9c7cafc4c2 100644 --- a/projects/example-app/src/app/books/actions/view-book-page.actions.ts +++ b/projects/example-app/src/app/books/actions/view-book-page.actions.ts @@ -1,6 +1,8 @@ -import { createAction, props } from '@ngrx/store'; +import { createActionGroup, props } from '@ngrx/store'; -export const selectBook = createAction( - '[View Book Page] Select Book', - props<{ id: string }>() -); +export const ViewBookPageActions = createActionGroup({ + source: 'View Book Page', + events: { + 'Select Book': props<{ id: string }>(), + }, +}); diff --git a/projects/example-app/src/app/books/containers/collection-page.component.spec.ts b/projects/example-app/src/app/books/containers/collection-page.component.spec.ts index cc6a862328..5addaa4aef 100644 --- a/projects/example-app/src/app/books/containers/collection-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/collection-page.component.spec.ts @@ -4,7 +4,7 @@ import { RouterTestingModule } from '@angular/router/testing'; import { MockStore, provideMockStore } from '@ngrx/store/testing'; -import { CollectionPageActions } from '@example-app/books/actions'; +import { CollectionPageActions } from '@example-app/books/actions/collection-page.actions'; import { BookAuthorsComponent, BookPreviewComponent, diff --git a/projects/example-app/src/app/books/containers/collection-page.component.ts b/projects/example-app/src/app/books/containers/collection-page.component.ts index f93722d17a..48acf84839 100644 --- a/projects/example-app/src/app/books/containers/collection-page.component.ts +++ b/projects/example-app/src/app/books/containers/collection-page.component.ts @@ -3,7 +3,7 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; -import { CollectionPageActions } from '@example-app/books/actions'; +import { CollectionPageActions } from '@example-app/books/actions/collection-page.actions'; import { Book } from '@example-app/books/models'; import * as fromBooks from '@example-app/books/reducers'; diff --git a/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts b/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts index cae827bbf2..719d1a31ae 100644 --- a/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/find-book-page.component.spec.ts @@ -5,7 +5,7 @@ import { RouterTestingModule } from '@angular/router/testing'; import { MockStore, provideMockStore } from '@ngrx/store/testing'; -import { FindBookPageActions } from '@example-app/books/actions'; +import { FindBookPageActions } from '@example-app/books/actions/find-book-page.actions'; import { BookAuthorsComponent, BookPreviewComponent, diff --git a/projects/example-app/src/app/books/containers/find-book-page.component.ts b/projects/example-app/src/app/books/containers/find-book-page.component.ts index 5f49798c6c..254727e58f 100644 --- a/projects/example-app/src/app/books/containers/find-book-page.component.ts +++ b/projects/example-app/src/app/books/containers/find-book-page.component.ts @@ -4,7 +4,7 @@ import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { take } from 'rxjs/operators'; -import { FindBookPageActions } from '@example-app/books/actions'; +import { FindBookPageActions } from '@example-app/books/actions/find-book-page.actions'; import { Book } from '@example-app/books/models'; import * as fromBooks from '@example-app/books/reducers'; diff --git a/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts b/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts index 25b38e420e..d3392db849 100644 --- a/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts @@ -3,7 +3,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { MockStore, provideMockStore } from '@ngrx/store/testing'; -import { SelectedBookPageActions } from '@example-app/books/actions'; +import { SelectedBookPageActions } from '@example-app/books/actions/selected-book-page.actions'; import { BookAuthorsComponent, BookDetailComponent, diff --git a/projects/example-app/src/app/books/containers/selected-book-page.component.ts b/projects/example-app/src/app/books/containers/selected-book-page.component.ts index 41e4abac01..292666869b 100644 --- a/projects/example-app/src/app/books/containers/selected-book-page.component.ts +++ b/projects/example-app/src/app/books/containers/selected-book-page.component.ts @@ -3,7 +3,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; -import { SelectedBookPageActions } from '@example-app/books/actions'; +import { SelectedBookPageActions } from '@example-app/books/actions/selected-book-page.actions'; import { Book } from '@example-app/books/models'; import * as fromBooks from '@example-app/books/reducers'; diff --git a/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts b/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts index 2b3f1ff052..b726b78e84 100644 --- a/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts +++ b/projects/example-app/src/app/books/containers/view-book-page.component.spec.ts @@ -10,7 +10,7 @@ import { } from '@example-app/books/components'; import { SelectedBookPageComponent } from '@example-app/books/containers'; import { ViewBookPageComponent } from '@example-app/books/containers'; -import { ViewBookPageActions } from '@example-app/books/actions'; +import { ViewBookPageActions } from '@example-app/books/actions/view-book-page.actions'; import { AddCommasPipe } from '@example-app/shared/pipes/add-commas.pipe'; import { MaterialModule } from '@example-app/material'; diff --git a/projects/example-app/src/app/books/containers/view-book-page.component.ts b/projects/example-app/src/app/books/containers/view-book-page.component.ts index 1431c61073..f4bf63b54c 100644 --- a/projects/example-app/src/app/books/containers/view-book-page.component.ts +++ b/projects/example-app/src/app/books/containers/view-book-page.component.ts @@ -4,7 +4,7 @@ import { Store } from '@ngrx/store'; import { Subscription } from 'rxjs'; import { map } from 'rxjs/operators'; -import { ViewBookPageActions } from '@example-app/books/actions'; +import { ViewBookPageActions } from '@example-app/books/actions/view-book-page.actions'; /** * Note: Container components are also reusable. Whether or not diff --git a/projects/example-app/src/app/books/effects/book.effects.spec.ts b/projects/example-app/src/app/books/effects/book.effects.spec.ts index 566a910ddb..18f8c845ab 100644 --- a/projects/example-app/src/app/books/effects/book.effects.spec.ts +++ b/projects/example-app/src/app/books/effects/book.effects.spec.ts @@ -5,10 +5,8 @@ import { provideMockActions } from '@ngrx/effects/testing'; import { cold, getTestScheduler, hot } from 'jasmine-marbles'; import { Observable } from 'rxjs'; -import { - BooksApiActions, - FindBookPageActions, -} from '@example-app/books/actions'; +import { FindBookPageActions } from '@example-app/books/actions/find-book-page.actions'; +import { BooksApiActions } from '@example-app/books/actions/books-api.actions'; import { BookEffects } from '@example-app/books/effects'; import { Book } from '@example-app/books/models'; import { GoogleBooksService } from '@example-app/core/services'; diff --git a/projects/example-app/src/app/books/effects/book.effects.ts b/projects/example-app/src/app/books/effects/book.effects.ts index 93a257d849..63aea38e7f 100644 --- a/projects/example-app/src/app/books/effects/book.effects.ts +++ b/projects/example-app/src/app/books/effects/book.effects.ts @@ -12,10 +12,8 @@ import { } from 'rxjs/operators'; import { Book } from '@example-app/books/models'; -import { - BooksApiActions, - FindBookPageActions, -} from '@example-app/books/actions'; +import { BooksApiActions } from '@example-app/books/actions/books-api.actions'; +import { FindBookPageActions } from '@example-app/books/actions/find-book-page.actions'; import { GoogleBooksService } from '@example-app/core/services'; /** diff --git a/projects/example-app/src/app/books/effects/collection.effects.spec.ts b/projects/example-app/src/app/books/effects/collection.effects.spec.ts index 54f72fad46..c2c6848f4e 100644 --- a/projects/example-app/src/app/books/effects/collection.effects.spec.ts +++ b/projects/example-app/src/app/books/effects/collection.effects.spec.ts @@ -1,10 +1,8 @@ import { TestBed } from '@angular/core/testing'; -import { - CollectionApiActions, - CollectionPageActions, - SelectedBookPageActions, -} from '@example-app/books/actions'; +import { CollectionApiActions } from '@example-app/books/actions/collection-api.actions'; +import { CollectionPageActions } from '@example-app/books/actions/collection-page.actions'; +import { SelectedBookPageActions } from '@example-app/books/actions/selected-book-page.actions'; import { CollectionEffects } from '@example-app/books/effects'; import { Book } from '@example-app/books/models'; import { diff --git a/projects/example-app/src/app/books/effects/collection.effects.ts b/projects/example-app/src/app/books/effects/collection.effects.ts index 91bc4ee5c2..a85711003d 100644 --- a/projects/example-app/src/app/books/effects/collection.effects.ts +++ b/projects/example-app/src/app/books/effects/collection.effects.ts @@ -4,11 +4,9 @@ import { Actions, createEffect, ofType } from '@ngrx/effects'; import { defer, of } from 'rxjs'; import { catchError, map, mergeMap, switchMap } from 'rxjs/operators'; -import { - CollectionApiActions, - CollectionPageActions, - SelectedBookPageActions, -} from '@example-app/books/actions'; +import { CollectionApiActions } from '@example-app/books/actions/collection-api.actions'; +import { CollectionPageActions } from '@example-app/books/actions/collection-page.actions'; +import { SelectedBookPageActions } from '@example-app/books/actions/selected-book-page.actions'; import { Book } from '@example-app/books/models'; import { BookStorageService } from '@example-app/core/services'; diff --git a/projects/example-app/src/app/books/guards/book-exists.guard.ts b/projects/example-app/src/app/books/guards/book-exists.guard.ts index fa8af38dab..a62e23759b 100644 --- a/projects/example-app/src/app/books/guards/book-exists.guard.ts +++ b/projects/example-app/src/app/books/guards/book-exists.guard.ts @@ -5,7 +5,7 @@ import { Observable, of } from 'rxjs'; import { catchError, filter, map, switchMap, take, tap } from 'rxjs/operators'; import { GoogleBooksService } from '@example-app/core/services'; -import { BookActions } from '@example-app/books/actions'; +import { BookActions } from '@example-app/books/actions/book.actions'; import * as fromBooks from '@example-app/books/reducers'; /** diff --git a/projects/example-app/src/app/books/reducers/books.reducer.spec.ts b/projects/example-app/src/app/books/reducers/books.reducer.spec.ts index 3b346a82da..089660df31 100644 --- a/projects/example-app/src/app/books/reducers/books.reducer.spec.ts +++ b/projects/example-app/src/app/books/reducers/books.reducer.spec.ts @@ -1,11 +1,9 @@ import { reducer } from '@example-app/books/reducers/books.reducer'; import * as fromBooks from '@example-app/books/reducers/books.reducer'; -import { - BooksApiActions, - BookActions, - ViewBookPageActions, - CollectionApiActions, -} from '@example-app/books/actions'; +import { BooksApiActions } from '@example-app/books/actions/books-api.actions'; +import { BookActions } from '@example-app/books/actions/book.actions'; +import { CollectionApiActions } from '@example-app/books/actions/collection-api.actions'; +import { ViewBookPageActions } from '@example-app/books/actions/view-book-page.actions'; import { Book, generateMockBook } from '@example-app/books/models'; describe('BooksReducer', () => { diff --git a/projects/example-app/src/app/books/reducers/books.reducer.ts b/projects/example-app/src/app/books/reducers/books.reducer.ts index ad07f315ff..30c01bae49 100644 --- a/projects/example-app/src/app/books/reducers/books.reducer.ts +++ b/projects/example-app/src/app/books/reducers/books.reducer.ts @@ -1,12 +1,10 @@ import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity'; import { createReducer, on } from '@ngrx/store'; -import { - BookActions, - BooksApiActions, - CollectionApiActions, - ViewBookPageActions, -} from '@example-app/books/actions'; +import { BooksApiActions } from '@example-app/books/actions/books-api.actions'; +import { BookActions } from '@example-app/books/actions/book.actions'; +import { CollectionApiActions } from '@example-app/books/actions/collection-api.actions'; +import { ViewBookPageActions } from '@example-app/books/actions/view-book-page.actions'; import { Book } from '@example-app/books/models'; export const booksFeatureKey = 'books'; diff --git a/projects/example-app/src/app/books/reducers/collection.reducer.ts b/projects/example-app/src/app/books/reducers/collection.reducer.ts index da11968058..f3a1408c48 100644 --- a/projects/example-app/src/app/books/reducers/collection.reducer.ts +++ b/projects/example-app/src/app/books/reducers/collection.reducer.ts @@ -1,10 +1,8 @@ import { createReducer, on } from '@ngrx/store'; -import { - CollectionApiActions, - CollectionPageActions, - SelectedBookPageActions, -} from '@example-app/books/actions'; +import { CollectionApiActions } from '@example-app/books/actions/collection-api.actions'; +import { CollectionPageActions } from '@example-app/books/actions/collection-page.actions'; +import { SelectedBookPageActions } from '@example-app/books/actions/selected-book-page.actions'; export const collectionFeatureKey = 'collection'; diff --git a/projects/example-app/src/app/books/reducers/search.reducer.ts b/projects/example-app/src/app/books/reducers/search.reducer.ts index 9d04208784..7bd9eca7e8 100644 --- a/projects/example-app/src/app/books/reducers/search.reducer.ts +++ b/projects/example-app/src/app/books/reducers/search.reducer.ts @@ -1,7 +1,5 @@ -import { - BooksApiActions, - FindBookPageActions, -} from '@example-app/books/actions'; +import { BooksApiActions } from '@example-app/books/actions/books-api.actions'; +import { FindBookPageActions } from '@example-app/books/actions/find-book-page.actions'; import { createReducer, on } from '@ngrx/store'; export const searchFeatureKey = 'search'; diff --git a/projects/example-app/src/app/core/actions/index.ts b/projects/example-app/src/app/core/actions/index.ts deleted file mode 100644 index e6323848b0..0000000000 --- a/projects/example-app/src/app/core/actions/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import * as LayoutActions from './layout.actions'; -import * as UserActions from './user.actions'; - -export { LayoutActions, UserActions }; diff --git a/projects/example-app/src/app/core/actions/layout.actions.ts b/projects/example-app/src/app/core/actions/layout.actions.ts index 5dcea4741c..1b8ce64588 100644 --- a/projects/example-app/src/app/core/actions/layout.actions.ts +++ b/projects/example-app/src/app/core/actions/layout.actions.ts @@ -1,4 +1,9 @@ -import { createAction } from '@ngrx/store'; +import { createActionGroup, emptyProps } from '@ngrx/store'; -export const openSidenav = createAction('[Layout] Open Sidenav'); -export const closeSidenav = createAction('[Layout] Close Sidenav'); +export const LayoutActions = createActionGroup({ + source: 'Layout', + events: { + 'Open Sidenav': emptyProps(), + 'Close Sidenav': emptyProps(), + }, +}); diff --git a/projects/example-app/src/app/core/actions/user.actions.ts b/projects/example-app/src/app/core/actions/user.actions.ts index 324a97e1d4..dfe10a913f 100644 --- a/projects/example-app/src/app/core/actions/user.actions.ts +++ b/projects/example-app/src/app/core/actions/user.actions.ts @@ -1,3 +1,8 @@ -import { createAction } from '@ngrx/store'; +import { createActionGroup, emptyProps } from '@ngrx/store'; -export const idleTimeout = createAction('[User] Idle Timeout'); +export const UserActions = createActionGroup({ + source: 'User', + events: { + 'Idle Timeout': emptyProps(), + }, +}); diff --git a/projects/example-app/src/app/core/containers/app.component.ts b/projects/example-app/src/app/core/containers/app.component.ts index 4dea160200..46a26eb8f0 100644 --- a/projects/example-app/src/app/core/containers/app.component.ts +++ b/projects/example-app/src/app/core/containers/app.component.ts @@ -2,10 +2,10 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; -import { AuthActions } from '@example-app/auth/actions'; +import { AuthActions } from '@example-app/auth/actions/auth.actions'; import * as fromAuth from '@example-app/auth/reducers'; import * as fromRoot from '@example-app/reducers'; -import { LayoutActions } from '@example-app/core/actions'; +import { LayoutActions } from '@example-app/core/actions/layout.actions'; @Component({ selector: 'bc-app', diff --git a/projects/example-app/src/app/core/effects/user.effects.spec.ts b/projects/example-app/src/app/core/effects/user.effects.spec.ts index ca31499f91..5aa06446af 100644 --- a/projects/example-app/src/app/core/effects/user.effects.spec.ts +++ b/projects/example-app/src/app/core/effects/user.effects.spec.ts @@ -2,7 +2,7 @@ import { Action } from '@ngrx/store'; import { TestBed, fakeAsync, tick } from '@angular/core/testing'; import { UserEffects } from '@example-app/core/effects'; -import { UserActions } from '@example-app/core/actions'; +import { UserActions } from '@example-app/core/actions/user.actions'; describe('UserEffects', () => { let effects: UserEffects; diff --git a/projects/example-app/src/app/core/effects/user.effects.ts b/projects/example-app/src/app/core/effects/user.effects.ts index fd2aef6cd5..1a96067006 100644 --- a/projects/example-app/src/app/core/effects/user.effects.ts +++ b/projects/example-app/src/app/core/effects/user.effects.ts @@ -4,7 +4,7 @@ import { fromEvent, merge, timer } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { createEffect } from '@ngrx/effects'; -import { UserActions } from '@example-app/core/actions'; +import { UserActions } from '@example-app/core/actions/user.actions'; @Injectable() export class UserEffects { diff --git a/projects/example-app/src/app/core/reducers/layout.reducer.ts b/projects/example-app/src/app/core/reducers/layout.reducer.ts index 3e175d2909..9b0a05ad7a 100644 --- a/projects/example-app/src/app/core/reducers/layout.reducer.ts +++ b/projects/example-app/src/app/core/reducers/layout.reducer.ts @@ -1,7 +1,7 @@ import { createReducer, on } from '@ngrx/store'; -import { LayoutActions } from '@example-app/core/actions'; -import { AuthActions } from '@example-app/auth/actions'; +import { LayoutActions } from '@example-app/core/actions/layout.actions'; +import { AuthActions } from '@example-app/auth/actions/auth.actions'; export const layoutFeatureKey = 'layout';