Skip to content

Commit b8ebe2e

Browse files
timdeschryverkrjordan
authored andcommitted
chore(Example): rename Actions to be consistent (#330)
1 parent ebf9cf4 commit b8ebe2e

File tree

14 files changed

+82
-90
lines changed

14 files changed

+82
-90
lines changed

example-app/app/books/actions/book.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ export const SELECT = '[Book] Select';
1313
*
1414
* See Discriminated Unions: https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions
1515
*/
16-
export class SearchAction implements Action {
16+
export class Search implements Action {
1717
readonly type = SEARCH;
1818

1919
constructor(public payload: string) {}
2020
}
2121

22-
export class SearchCompleteAction implements Action {
22+
export class SearchComplete implements Action {
2323
readonly type = SEARCH_COMPLETE;
2424

2525
constructor(public payload: Book[]) {}
2626
}
2727

28-
export class LoadAction implements Action {
28+
export class Load implements Action {
2929
readonly type = LOAD;
3030

3131
constructor(public payload: Book) {}
3232
}
3333

34-
export class SelectAction implements Action {
34+
export class Select implements Action {
3535
readonly type = SELECT;
3636

3737
constructor(public payload: string) {}
@@ -41,8 +41,4 @@ export class SelectAction implements Action {
4141
* Export a type alias of all actions in this action group
4242
* so that reducers can easily compose action types
4343
*/
44-
export type Actions =
45-
| SearchAction
46-
| SearchCompleteAction
47-
| LoadAction
48-
| SelectAction;
44+
export type Actions = Search | SearchComplete | Load | Select;

example-app/app/books/actions/collection.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ export const LOAD_FAIL = '[Collection] Load Fail';
1414
/**
1515
* Add Book to Collection Actions
1616
*/
17-
export class AddBookAction implements Action {
17+
export class AddBook implements Action {
1818
readonly type = ADD_BOOK;
1919

2020
constructor(public payload: Book) {}
2121
}
2222

23-
export class AddBookSuccessAction implements Action {
23+
export class AddBookSuccess implements Action {
2424
readonly type = ADD_BOOK_SUCCESS;
2525

2626
constructor(public payload: Book) {}
2727
}
2828

29-
export class AddBookFailAction implements Action {
29+
export class AddBookFail implements Action {
3030
readonly type = ADD_BOOK_FAIL;
3131

3232
constructor(public payload: Book) {}
@@ -35,19 +35,19 @@ export class AddBookFailAction implements Action {
3535
/**
3636
* Remove Book from Collection Actions
3737
*/
38-
export class RemoveBookAction implements Action {
38+
export class RemoveBook implements Action {
3939
readonly type = REMOVE_BOOK;
4040

4141
constructor(public payload: Book) {}
4242
}
4343

44-
export class RemoveBookSuccessAction implements Action {
44+
export class RemoveBookSuccess implements Action {
4545
readonly type = REMOVE_BOOK_SUCCESS;
4646

4747
constructor(public payload: Book) {}
4848
}
4949

50-
export class RemoveBookFailAction implements Action {
50+
export class RemoveBookFail implements Action {
5151
readonly type = REMOVE_BOOK_FAIL;
5252

5353
constructor(public payload: Book) {}
@@ -56,29 +56,29 @@ export class RemoveBookFailAction implements Action {
5656
/**
5757
* Load Collection Actions
5858
*/
59-
export class LoadAction implements Action {
59+
export class Load implements Action {
6060
readonly type = LOAD;
6161
}
6262

63-
export class LoadSuccessAction implements Action {
63+
export class LoadSuccess implements Action {
6464
readonly type = LOAD_SUCCESS;
6565

6666
constructor(public payload: Book[]) {}
6767
}
6868

69-
export class LoadFailAction implements Action {
69+
export class LoadFail implements Action {
7070
readonly type = LOAD_FAIL;
7171

7272
constructor(public payload: any) {}
7373
}
7474

7575
export type Actions =
76-
| AddBookAction
77-
| AddBookSuccessAction
78-
| AddBookFailAction
79-
| RemoveBookAction
80-
| RemoveBookSuccessAction
81-
| RemoveBookFailAction
82-
| LoadAction
83-
| LoadSuccessAction
84-
| LoadFailAction;
76+
| AddBook
77+
| AddBookSuccess
78+
| AddBookFail
79+
| RemoveBook
80+
| RemoveBookSuccess
81+
| RemoveBookFail
82+
| Load
83+
| LoadSuccess
84+
| LoadFail;

example-app/app/books/containers/collection-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ export class CollectionPageComponent implements OnInit {
4040
}
4141

4242
ngOnInit() {
43-
this.store.dispatch(new collection.LoadAction());
43+
this.store.dispatch(new collection.Load());
4444
}
4545
}

example-app/app/books/containers/find-book-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export class FindBookPageComponent {
2727
}
2828

2929
search(query: string) {
30-
this.store.dispatch(new book.SearchAction(query));
30+
this.store.dispatch(new book.Search(query));
3131
}
3232
}

example-app/app/books/containers/selected-book-page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export class SelectedBookPageComponent {
3030
}
3131

3232
addToCollection(book: Book) {
33-
this.store.dispatch(new collection.AddBookAction(book));
33+
this.store.dispatch(new collection.AddBook(book));
3434
}
3535

3636
removeFromCollection(book: Book) {
37-
this.store.dispatch(new collection.RemoveBookAction(book));
37+
this.store.dispatch(new collection.RemoveBook(book));
3838
}
3939
}

example-app/app/books/containers/view-book-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class ViewBookPageComponent implements OnDestroy {
3030

3131
constructor(store: Store<fromBooks.State>, route: ActivatedRoute) {
3232
this.actionsSubscription = route.params
33-
.map(params => new book.SelectAction(params.id))
33+
.map(params => new book.Select(params.id))
3434
.subscribe(store);
3535
}
3636

example-app/app/books/effects/book.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { empty } from 'rxjs/observable/empty';
55
import { BookEffects, SEARCH_SCHEDULER, SEARCH_DEBOUNCE } from './book';
66
import { GoogleBooksService } from '../../core/services/google-books';
77
import { Observable } from 'rxjs/Observable';
8-
import { SearchAction, SearchCompleteAction } from '../actions/book';
8+
import { Search, SearchComplete } from '../actions/book';
99
import { Book } from '../models/book';
1010

1111
export class TestActions extends Actions {
@@ -47,12 +47,12 @@ describe('BookEffects', () => {
4747
});
4848

4949
describe('search$', () => {
50-
it('should return a new book.SearchCompleteAction, with the books, on success, after the de-bounce', () => {
50+
it('should return a new book.SearchComplete, with the books, on success, after the de-bounce', () => {
5151
const book1 = { id: '111', volumeInfo: {} } as Book;
5252
const book2 = { id: '222', volumeInfo: {} } as Book;
5353
const books = [book1, book2];
54-
const action = new SearchAction('query');
55-
const completion = new SearchCompleteAction(books);
54+
const action = new Search('query');
55+
const completion = new SearchComplete(books);
5656

5757
actions$.stream = hot('-a---', { a: action });
5858
const response = cold('-a|', { a: books });
@@ -62,9 +62,9 @@ describe('BookEffects', () => {
6262
expect(effects.search$).toBeObservable(expected);
6363
});
6464

65-
it('should return a new book.SearchCompleteAction, with an empty array, if the books service throws', () => {
66-
const action = new SearchAction('query');
67-
const completion = new SearchCompleteAction([]);
65+
it('should return a new book.SearchComplete, with an empty array, if the books service throws', () => {
66+
const action = new Search('query');
67+
const completion = new SearchComplete([]);
6868
const error = 'Error!';
6969

7070
actions$.stream = hot('-a---', { a: action });
@@ -76,7 +76,7 @@ describe('BookEffects', () => {
7676
});
7777

7878
it(`should not do anything if the query is an empty string`, () => {
79-
const action = new SearchAction('');
79+
const action = new Search('');
8080

8181
actions$.stream = hot('-a---', { a: action });
8282
const expected = cold('---');

example-app/app/books/effects/book.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const SEARCH_SCHEDULER = new InjectionToken<Scheduler>(
3737
export class BookEffects {
3838
@Effect()
3939
search$: Observable<Action> = this.actions$
40-
.ofType<book.SearchAction>(book.SEARCH)
40+
.ofType<book.Search>(book.SEARCH)
4141
.debounceTime(this.debounce, this.scheduler || async)
4242
.map(action => action.payload)
4343
.switchMap(query => {
@@ -50,8 +50,8 @@ export class BookEffects {
5050
return this.googleBooks
5151
.searchBooks(query)
5252
.takeUntil(nextSearch$)
53-
.map((books: Book[]) => new book.SearchCompleteAction(books))
54-
.catch(() => of(new book.SearchCompleteAction([])));
53+
.map((books: Book[]) => new book.SearchComplete(books))
54+
.catch(() => of(new book.SearchComplete([])));
5555
});
5656

5757
constructor(

example-app/app/books/effects/collection.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ describe('CollectionEffects', () => {
6060
});
6161

6262
describe('loadCollection$', () => {
63-
it('should return a collection.LoadSuccessAction, with the books, on success', () => {
64-
const action = new collection.LoadAction();
65-
const completion = new collection.LoadSuccessAction([book1, book2]);
63+
it('should return a collection.LoadSuccess, with the books, on success', () => {
64+
const action = new collection.Load();
65+
const completion = new collection.LoadSuccess([book1, book2]);
6666

6767
actions$.stream = hot('-a', { a: action });
6868
const response = cold('-a-b|', { a: book1, b: book2 });
@@ -72,10 +72,10 @@ describe('CollectionEffects', () => {
7272
expect(effects.loadCollection$).toBeObservable(expected);
7373
});
7474

75-
it('should return a collection.LoadFailAction, if the query throws', () => {
76-
const action = new collection.LoadAction();
75+
it('should return a collection.LoadFail, if the query throws', () => {
76+
const action = new collection.Load();
7777
const error = 'Error!';
78-
const completion = new collection.LoadFailAction(error);
78+
const completion = new collection.LoadFail(error);
7979

8080
actions$.stream = hot('-a', { a: action });
8181
const response = cold('-#', {}, error);
@@ -87,9 +87,9 @@ describe('CollectionEffects', () => {
8787
});
8888

8989
describe('addBookToCollection$', () => {
90-
it('should return a collection.AddBookSuccessAction, with the book, on success', () => {
91-
const action = new collection.AddBookAction(book1);
92-
const completion = new collection.AddBookSuccessAction(book1);
90+
it('should return a collection.AddBookSuccess, with the book, on success', () => {
91+
const action = new collection.AddBook(book1);
92+
const completion = new collection.AddBookSuccess(book1);
9393

9494
actions$.stream = hot('-a', { a: action });
9595
const response = cold('-b', { b: true });
@@ -100,9 +100,9 @@ describe('CollectionEffects', () => {
100100
expect(db.insert).toHaveBeenCalledWith('books', [book1]);
101101
});
102102

103-
it('should return a collection.AddBookFailAction, with the book, when the db insert throws', () => {
104-
const action = new collection.AddBookAction(book1);
105-
const completion = new collection.AddBookFailAction(book1);
103+
it('should return a collection.AddBookFail, with the book, when the db insert throws', () => {
104+
const action = new collection.AddBook(book1);
105+
const completion = new collection.AddBookFail(book1);
106106
const error = 'Error!';
107107

108108
actions$.stream = hot('-a', { a: action });
@@ -114,9 +114,9 @@ describe('CollectionEffects', () => {
114114
});
115115

116116
describe('removeBookFromCollection$', () => {
117-
it('should return a collection.RemoveBookSuccessAction, with the book, on success', () => {
118-
const action = new collection.RemoveBookAction(book1);
119-
const completion = new collection.RemoveBookSuccessAction(book1);
117+
it('should return a collection.RemoveBookSuccess, with the book, on success', () => {
118+
const action = new collection.RemoveBook(book1);
119+
const completion = new collection.RemoveBookSuccess(book1);
120120

121121
actions$.stream = hot('-a', { a: action });
122122
const response = cold('-b', { b: true });
@@ -129,9 +129,9 @@ describe('CollectionEffects', () => {
129129
]);
130130
});
131131

132-
it('should return a collection.RemoveBookFailAction, with the book, when the db insert throws', () => {
133-
const action = new collection.RemoveBookAction(book1);
134-
const completion = new collection.RemoveBookFailAction(book1);
132+
it('should return a collection.RemoveBookFail, with the book, when the db insert throws', () => {
133+
const action = new collection.RemoveBook(book1);
134+
const completion = new collection.RemoveBookFail(book1);
135135
const error = 'Error!';
136136

137137
actions$.stream = hot('-a', { a: action });

example-app/app/books/effects/collection.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,30 @@ export class CollectionEffects {
3838
this.db
3939
.query('books')
4040
.toArray()
41-
.map((books: Book[]) => new collection.LoadSuccessAction(books))
42-
.catch(error => of(new collection.LoadFailAction(error)))
41+
.map((books: Book[]) => new collection.LoadSuccess(books))
42+
.catch(error => of(new collection.LoadFail(error)))
4343
);
4444

4545
@Effect()
4646
addBookToCollection$: Observable<Action> = this.actions$
4747
.ofType(collection.ADD_BOOK)
48-
.map((action: collection.AddBookAction) => action.payload)
48+
.map((action: collection.AddBook) => action.payload)
4949
.mergeMap(book =>
5050
this.db
5151
.insert('books', [book])
52-
.map(() => new collection.AddBookSuccessAction(book))
53-
.catch(() => of(new collection.AddBookFailAction(book)))
52+
.map(() => new collection.AddBookSuccess(book))
53+
.catch(() => of(new collection.AddBookFail(book)))
5454
);
5555

5656
@Effect()
5757
removeBookFromCollection$: Observable<Action> = this.actions$
5858
.ofType(collection.REMOVE_BOOK)
59-
.map((action: collection.RemoveBookAction) => action.payload)
59+
.map((action: collection.RemoveBook) => action.payload)
6060
.mergeMap(book =>
6161
this.db
6262
.executeWrite('books', 'delete', [book.id])
63-
.map(() => new collection.RemoveBookSuccessAction(book))
64-
.catch(() => of(new collection.RemoveBookFailAction(book)))
63+
.map(() => new collection.RemoveBookSuccess(book))
64+
.catch(() => of(new collection.RemoveBookFail(book)))
6565
);
6666

6767
constructor(private actions$: Actions, private db: Database) {}

0 commit comments

Comments
 (0)