This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** see below - comment is required for all exported symbols */ | |
export const LOGIN = '[Login Page] Login', | |
interface LoginPayload { | |
username: string; | |
password: string; | |
} | |
/** Action to log in the User from the Login Page */ | |
export class Login implements Action { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export enum ActionTypes { | |
Login = '[Login Page] Login', | |
} | |
export class Login implements Action { | |
readonly type = ActionTypes.Login; | |
constructor(public payload: { username: string; password: string }) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const isLoading = createSelector( | |
getResultState, | |
state => state.callState === CallState.LOADING, | |
); | |
export const isLoaded = createSelector( | |
getResultState, | |
state => state.callState === CallState.LOADED, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ResultState { | |
result: Result|null, | |
callState: CallState; | |
} | |
const initState: ResultState = { | |
result: null, | |
callState: LoadingState.INIT, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dispatch is set to false, so this effect will not try to dispatch | |
// the result of this effect. | |
@Effect({ dispatch: false }) | |
handleFetchError: Observable<unknown> = this.actions$.pipe( | |
ofType(actions.FETCH_PRODUCTS_ERROR), | |
map(() => { | |
// Setting the timeout, so that angular would re-run change detection. | |
setTimeout( | |
() => | |
this.snackBar.open('Error fetching products', 'Error', { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-movies-page', | |
template: ` | |
<h1>Movies Page</h1> | |
<div *ngIf="error$ | async as error"> | |
{{ error }} | |
</div> | |
<button (click)="reload()">Refresh List</button> | |
` | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function reducer( | |
state: CartState = initState, | |
action: cartActions.All | |
): CartState { | |
switch (action.type) { | |
case cartActions.ADD_ITEM: { | |
// Concatinating the id to the list | |
const newCartItemsIds = [...state.cartItemsIds, action.itemId]; | |
return { | |
cartItemsIds: newCartItemsIds, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Effect() | |
addComment: Observable<Action> = this.actions.pipe( | |
ofType(actions.ADD_COMMENT), | |
concatMap( | |
({payload}) => | |
this.commentsService.add(payload.productId, payload.comment) | |
.pipe( | |
map(response => new actions.AddCommentSuccess()), | |
catchError( | |
error => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Effect() | |
handleAddCommentError: Observable<Action> = this.actions.pipe( | |
ofType(actions.ADD_COMMENT_ERROR), | |
map(({payload}) => new actions.ShowAddCommentDialog(payload)), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Effect() | |
showAddCommentDialog: Observable<Action> = this.actions.pipe( | |
ofType(actions.SHOW_ADD_COMMENT_DIALOG), | |
withLatestFrom( | |
this.store.select(selectors.getCurrentProductId)), | |
concatMap( | |
([{payload}, productId]) => | |
this.dialog.open(AddCommentDialog, {data: payload}) | |
.afterClosed() | |
.pipe( |