diff --git a/example-app/app/books/actions/book.ts b/example-app/app/books/actions/book.ts index e13684906f..e1735e87fb 100644 --- a/example-app/app/books/actions/book.ts +++ b/example-app/app/books/actions/book.ts @@ -13,25 +13,25 @@ export const SELECT = '[Book] Select'; * * See Discriminated Unions: https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions */ -export class SearchAction implements Action { +export class Search implements Action { readonly type = SEARCH; constructor(public payload: string) {} } -export class SearchCompleteAction implements Action { +export class SearchComplete implements Action { readonly type = SEARCH_COMPLETE; constructor(public payload: Book[]) {} } -export class LoadAction implements Action { +export class Load implements Action { readonly type = LOAD; constructor(public payload: Book) {} } -export class SelectAction implements Action { +export class Select implements Action { readonly type = SELECT; constructor(public payload: string) {} @@ -41,8 +41,4 @@ export class SelectAction implements Action { * Export a type alias of all actions in this action group * so that reducers can easily compose action types */ -export type Actions = - | SearchAction - | SearchCompleteAction - | LoadAction - | SelectAction; +export type Actions = Search | SearchComplete | Load | Select; diff --git a/example-app/app/books/actions/collection.ts b/example-app/app/books/actions/collection.ts index 4cd1c898ec..7de653bc16 100644 --- a/example-app/app/books/actions/collection.ts +++ b/example-app/app/books/actions/collection.ts @@ -14,19 +14,19 @@ export const LOAD_FAIL = '[Collection] Load Fail'; /** * Add Book to Collection Actions */ -export class AddBookAction implements Action { +export class AddBook implements Action { readonly type = ADD_BOOK; constructor(public payload: Book) {} } -export class AddBookSuccessAction implements Action { +export class AddBookSuccess implements Action { readonly type = ADD_BOOK_SUCCESS; constructor(public payload: Book) {} } -export class AddBookFailAction implements Action { +export class AddBookFail implements Action { readonly type = ADD_BOOK_FAIL; constructor(public payload: Book) {} @@ -35,19 +35,19 @@ export class AddBookFailAction implements Action { /** * Remove Book from Collection Actions */ -export class RemoveBookAction implements Action { +export class RemoveBook implements Action { readonly type = REMOVE_BOOK; constructor(public payload: Book) {} } -export class RemoveBookSuccessAction implements Action { +export class RemoveBookSuccess implements Action { readonly type = REMOVE_BOOK_SUCCESS; constructor(public payload: Book) {} } -export class RemoveBookFailAction implements Action { +export class RemoveBookFail implements Action { readonly type = REMOVE_BOOK_FAIL; constructor(public payload: Book) {} @@ -56,29 +56,29 @@ export class RemoveBookFailAction implements Action { /** * Load Collection Actions */ -export class LoadAction implements Action { +export class Load implements Action { readonly type = LOAD; } -export class LoadSuccessAction implements Action { +export class LoadSuccess implements Action { readonly type = LOAD_SUCCESS; constructor(public payload: Book[]) {} } -export class LoadFailAction implements Action { +export class LoadFail implements Action { readonly type = LOAD_FAIL; constructor(public payload: any) {} } export type Actions = - | AddBookAction - | AddBookSuccessAction - | AddBookFailAction - | RemoveBookAction - | RemoveBookSuccessAction - | RemoveBookFailAction - | LoadAction - | LoadSuccessAction - | LoadFailAction; + | AddBook + | AddBookSuccess + | AddBookFail + | RemoveBook + | RemoveBookSuccess + | RemoveBookFail + | Load + | LoadSuccess + | LoadFail; diff --git a/example-app/app/books/containers/collection-page.ts b/example-app/app/books/containers/collection-page.ts index 89876c77f7..f4c61e9e32 100644 --- a/example-app/app/books/containers/collection-page.ts +++ b/example-app/app/books/containers/collection-page.ts @@ -40,6 +40,6 @@ export class CollectionPageComponent implements OnInit { } ngOnInit() { - this.store.dispatch(new collection.LoadAction()); + this.store.dispatch(new collection.Load()); } } diff --git a/example-app/app/books/containers/find-book-page.ts b/example-app/app/books/containers/find-book-page.ts index d24d01be03..86fda79483 100644 --- a/example-app/app/books/containers/find-book-page.ts +++ b/example-app/app/books/containers/find-book-page.ts @@ -27,6 +27,6 @@ export class FindBookPageComponent { } search(query: string) { - this.store.dispatch(new book.SearchAction(query)); + this.store.dispatch(new book.Search(query)); } } diff --git a/example-app/app/books/containers/selected-book-page.ts b/example-app/app/books/containers/selected-book-page.ts index d271ba1989..5fd8579ca9 100644 --- a/example-app/app/books/containers/selected-book-page.ts +++ b/example-app/app/books/containers/selected-book-page.ts @@ -30,10 +30,10 @@ export class SelectedBookPageComponent { } addToCollection(book: Book) { - this.store.dispatch(new collection.AddBookAction(book)); + this.store.dispatch(new collection.AddBook(book)); } removeFromCollection(book: Book) { - this.store.dispatch(new collection.RemoveBookAction(book)); + this.store.dispatch(new collection.RemoveBook(book)); } } diff --git a/example-app/app/books/containers/view-book-page.ts b/example-app/app/books/containers/view-book-page.ts index 6acd0a73b3..f879d84ee4 100644 --- a/example-app/app/books/containers/view-book-page.ts +++ b/example-app/app/books/containers/view-book-page.ts @@ -30,7 +30,7 @@ export class ViewBookPageComponent implements OnDestroy { constructor(store: Store, route: ActivatedRoute) { this.actionsSubscription = route.params - .map(params => new book.SelectAction(params.id)) + .map(params => new book.Select(params.id)) .subscribe(store); } diff --git a/example-app/app/books/effects/book.spec.ts b/example-app/app/books/effects/book.spec.ts index e5b2ce3c12..dbe58a4bf5 100644 --- a/example-app/app/books/effects/book.spec.ts +++ b/example-app/app/books/effects/book.spec.ts @@ -5,7 +5,7 @@ import { empty } from 'rxjs/observable/empty'; import { BookEffects, SEARCH_SCHEDULER, SEARCH_DEBOUNCE } from './book'; import { GoogleBooksService } from '../../core/services/google-books'; import { Observable } from 'rxjs/Observable'; -import { SearchAction, SearchCompleteAction } from '../actions/book'; +import { Search, SearchComplete } from '../actions/book'; import { Book } from '../models/book'; export class TestActions extends Actions { @@ -47,12 +47,12 @@ describe('BookEffects', () => { }); describe('search$', () => { - it('should return a new book.SearchCompleteAction, with the books, on success, after the de-bounce', () => { + it('should return a new book.SearchComplete, with the books, on success, after the de-bounce', () => { const book1 = { id: '111', volumeInfo: {} } as Book; const book2 = { id: '222', volumeInfo: {} } as Book; const books = [book1, book2]; - const action = new SearchAction('query'); - const completion = new SearchCompleteAction(books); + const action = new Search('query'); + const completion = new SearchComplete(books); actions$.stream = hot('-a---', { a: action }); const response = cold('-a|', { a: books }); @@ -62,9 +62,9 @@ describe('BookEffects', () => { expect(effects.search$).toBeObservable(expected); }); - it('should return a new book.SearchCompleteAction, with an empty array, if the books service throws', () => { - const action = new SearchAction('query'); - const completion = new SearchCompleteAction([]); + it('should return a new book.SearchComplete, with an empty array, if the books service throws', () => { + const action = new Search('query'); + const completion = new SearchComplete([]); const error = 'Error!'; actions$.stream = hot('-a---', { a: action }); @@ -76,7 +76,7 @@ describe('BookEffects', () => { }); it(`should not do anything if the query is an empty string`, () => { - const action = new SearchAction(''); + const action = new Search(''); actions$.stream = hot('-a---', { a: action }); const expected = cold('---'); diff --git a/example-app/app/books/effects/book.ts b/example-app/app/books/effects/book.ts index 76cee2e628..75804c8347 100644 --- a/example-app/app/books/effects/book.ts +++ b/example-app/app/books/effects/book.ts @@ -37,7 +37,7 @@ export const SEARCH_SCHEDULER = new InjectionToken( export class BookEffects { @Effect() search$: Observable = this.actions$ - .ofType(book.SEARCH) + .ofType(book.SEARCH) .debounceTime(this.debounce, this.scheduler || async) .map(action => action.payload) .switchMap(query => { @@ -50,8 +50,8 @@ export class BookEffects { return this.googleBooks .searchBooks(query) .takeUntil(nextSearch$) - .map((books: Book[]) => new book.SearchCompleteAction(books)) - .catch(() => of(new book.SearchCompleteAction([]))); + .map((books: Book[]) => new book.SearchComplete(books)) + .catch(() => of(new book.SearchComplete([]))); }); constructor( diff --git a/example-app/app/books/effects/collection.spec.ts b/example-app/app/books/effects/collection.spec.ts index 3ff6954e3d..c2a4eb8774 100644 --- a/example-app/app/books/effects/collection.spec.ts +++ b/example-app/app/books/effects/collection.spec.ts @@ -60,9 +60,9 @@ describe('CollectionEffects', () => { }); describe('loadCollection$', () => { - it('should return a collection.LoadSuccessAction, with the books, on success', () => { - const action = new collection.LoadAction(); - const completion = new collection.LoadSuccessAction([book1, book2]); + it('should return a collection.LoadSuccess, with the books, on success', () => { + const action = new collection.Load(); + const completion = new collection.LoadSuccess([book1, book2]); actions$.stream = hot('-a', { a: action }); const response = cold('-a-b|', { a: book1, b: book2 }); @@ -72,10 +72,10 @@ describe('CollectionEffects', () => { expect(effects.loadCollection$).toBeObservable(expected); }); - it('should return a collection.LoadFailAction, if the query throws', () => { - const action = new collection.LoadAction(); + it('should return a collection.LoadFail, if the query throws', () => { + const action = new collection.Load(); const error = 'Error!'; - const completion = new collection.LoadFailAction(error); + const completion = new collection.LoadFail(error); actions$.stream = hot('-a', { a: action }); const response = cold('-#', {}, error); @@ -87,9 +87,9 @@ describe('CollectionEffects', () => { }); describe('addBookToCollection$', () => { - it('should return a collection.AddBookSuccessAction, with the book, on success', () => { - const action = new collection.AddBookAction(book1); - const completion = new collection.AddBookSuccessAction(book1); + it('should return a collection.AddBookSuccess, with the book, on success', () => { + const action = new collection.AddBook(book1); + const completion = new collection.AddBookSuccess(book1); actions$.stream = hot('-a', { a: action }); const response = cold('-b', { b: true }); @@ -100,9 +100,9 @@ describe('CollectionEffects', () => { expect(db.insert).toHaveBeenCalledWith('books', [book1]); }); - it('should return a collection.AddBookFailAction, with the book, when the db insert throws', () => { - const action = new collection.AddBookAction(book1); - const completion = new collection.AddBookFailAction(book1); + it('should return a collection.AddBookFail, with the book, when the db insert throws', () => { + const action = new collection.AddBook(book1); + const completion = new collection.AddBookFail(book1); const error = 'Error!'; actions$.stream = hot('-a', { a: action }); @@ -114,9 +114,9 @@ describe('CollectionEffects', () => { }); describe('removeBookFromCollection$', () => { - it('should return a collection.RemoveBookSuccessAction, with the book, on success', () => { - const action = new collection.RemoveBookAction(book1); - const completion = new collection.RemoveBookSuccessAction(book1); + it('should return a collection.RemoveBookSuccess, with the book, on success', () => { + const action = new collection.RemoveBook(book1); + const completion = new collection.RemoveBookSuccess(book1); actions$.stream = hot('-a', { a: action }); const response = cold('-b', { b: true }); @@ -129,9 +129,9 @@ describe('CollectionEffects', () => { ]); }); - it('should return a collection.RemoveBookFailAction, with the book, when the db insert throws', () => { - const action = new collection.RemoveBookAction(book1); - const completion = new collection.RemoveBookFailAction(book1); + it('should return a collection.RemoveBookFail, with the book, when the db insert throws', () => { + const action = new collection.RemoveBook(book1); + const completion = new collection.RemoveBookFail(book1); const error = 'Error!'; actions$.stream = hot('-a', { a: action }); diff --git a/example-app/app/books/effects/collection.ts b/example-app/app/books/effects/collection.ts index d14ecebba3..a86c8c11c3 100644 --- a/example-app/app/books/effects/collection.ts +++ b/example-app/app/books/effects/collection.ts @@ -38,30 +38,30 @@ export class CollectionEffects { this.db .query('books') .toArray() - .map((books: Book[]) => new collection.LoadSuccessAction(books)) - .catch(error => of(new collection.LoadFailAction(error))) + .map((books: Book[]) => new collection.LoadSuccess(books)) + .catch(error => of(new collection.LoadFail(error))) ); @Effect() addBookToCollection$: Observable = this.actions$ .ofType(collection.ADD_BOOK) - .map((action: collection.AddBookAction) => action.payload) + .map((action: collection.AddBook) => action.payload) .mergeMap(book => this.db .insert('books', [book]) - .map(() => new collection.AddBookSuccessAction(book)) - .catch(() => of(new collection.AddBookFailAction(book))) + .map(() => new collection.AddBookSuccess(book)) + .catch(() => of(new collection.AddBookFail(book))) ); @Effect() removeBookFromCollection$: Observable = this.actions$ .ofType(collection.REMOVE_BOOK) - .map((action: collection.RemoveBookAction) => action.payload) + .map((action: collection.RemoveBook) => action.payload) .mergeMap(book => this.db .executeWrite('books', 'delete', [book.id]) - .map(() => new collection.RemoveBookSuccessAction(book)) - .catch(() => of(new collection.RemoveBookFailAction(book))) + .map(() => new collection.RemoveBookSuccess(book)) + .catch(() => of(new collection.RemoveBookFail(book))) ); constructor(private actions$: Actions, private db: Database) {} diff --git a/example-app/app/books/guards/book-exists.ts b/example-app/app/books/guards/book-exists.ts index 1d5d5aebc0..469f51a324 100644 --- a/example-app/app/books/guards/book-exists.ts +++ b/example-app/app/books/guards/book-exists.ts @@ -58,8 +58,8 @@ export class BookExistsGuard implements CanActivate { hasBookInApi(id: string): Observable { return this.googleBooks .retrieveBook(id) - .map(bookEntity => new book.LoadAction(bookEntity)) - .do((action: book.LoadAction) => this.store.dispatch(action)) + .map(bookEntity => new book.Load(bookEntity)) + .do((action: book.Load) => this.store.dispatch(action)) .map(book => !!book) .catch(() => { this.router.navigate(['/404']); diff --git a/example-app/app/books/reducers/book.spec.ts b/example-app/app/books/reducers/book.spec.ts index f5e280fc4e..45650f4119 100644 --- a/example-app/app/books/reducers/book.spec.ts +++ b/example-app/app/books/reducers/book.spec.ts @@ -1,12 +1,8 @@ import { reducer } from './books'; import * as fromBooks from './books'; -import { - SearchCompleteAction, - LoadAction, - SelectAction, -} from '../actions/book'; +import { SearchComplete, Load, Select } from '../actions/book'; import { Book } from '../models/book'; -import { LoadSuccessAction } from '../actions/collection'; +import { LoadSuccess } from '../actions/collection'; describe('BooksReducer', () => { describe('undefined action', () => { @@ -68,20 +64,20 @@ describe('BooksReducer', () => { } it('should add all books in the payload when none exist', () => { - noExistingBooks(SearchCompleteAction); - noExistingBooks(LoadSuccessAction); + noExistingBooks(SearchComplete); + noExistingBooks(LoadSuccess); }); it('should add only new books when books already exist', () => { - existingBooks(SearchCompleteAction); - existingBooks(LoadSuccessAction); + existingBooks(SearchComplete); + existingBooks(LoadSuccess); }); }); describe('LOAD', () => { it('should add a single book, if the book does not exist', () => { const book = { id: '888' } as Book; - const action = new LoadAction(book); + const action = new Load(book); const expectedResult = { ids: ['888'], @@ -103,7 +99,7 @@ describe('BooksReducer', () => { }, } as any; const book = { id: '999', foo: 'baz' } as any; - const action = new LoadAction(book); + const action = new Load(book); const result = reducer(initialState, action); expect(result).toEqual(initialState); @@ -112,7 +108,7 @@ describe('BooksReducer', () => { describe('SELECT', () => { it('should set the selected book id on the state', () => { - const action = new SelectAction('1'); + const action = new Select('1'); const result = reducer(fromBooks.initialState, action); expect(result.selectedBookId).toBe('1'); diff --git a/example-app/app/core/actions/layout.ts b/example-app/app/core/actions/layout.ts index 9dcc2aeaee..6331f55d81 100644 --- a/example-app/app/core/actions/layout.ts +++ b/example-app/app/core/actions/layout.ts @@ -3,12 +3,12 @@ import { Action } from '@ngrx/store'; export const OPEN_SIDENAV = '[Layout] Open Sidenav'; export const CLOSE_SIDENAV = '[Layout] Close Sidenav'; -export class OpenSidenavAction implements Action { +export class OpenSidenav implements Action { readonly type = OPEN_SIDENAV; } -export class CloseSidenavAction implements Action { +export class CloseSidenav implements Action { readonly type = CLOSE_SIDENAV; } -export type Actions = OpenSidenavAction | CloseSidenavAction; +export type Actions = OpenSidenav | CloseSidenav; diff --git a/example-app/app/core/containers/app.ts b/example-app/app/core/containers/app.ts index 9643af4d60..ca7722adcf 100644 --- a/example-app/app/core/containers/app.ts +++ b/example-app/app/core/containers/app.ts @@ -22,7 +22,7 @@ import * as Auth from '../../auth/actions/auth'; Sign In - + Sign Out @@ -55,11 +55,11 @@ export class AppComponent { * updates and user interaction through the life of our * application. */ - this.store.dispatch(new layout.CloseSidenavAction()); + this.store.dispatch(new layout.CloseSidenav()); } openSidenav() { - this.store.dispatch(new layout.OpenSidenavAction()); + this.store.dispatch(new layout.OpenSidenav()); } logout() {