-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-movie.reducer.ts
More file actions
31 lines (27 loc) · 824 Bytes
/
new-movie.reducer.ts
File metadata and controls
31 lines (27 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Action, createReducer, on } from '@ngrx/store';
import * as NewMovieActions from './new-movie.actions';
import { TMDBMovie } from '../movies/tmdb-result';
export interface State {
searching: boolean;
searchResults: TMDBMovie[];
}
export const initialState: State = {
searching: false,
searchResults: [],
};
const newMovieReducer = createReducer(
initialState,
on(NewMovieActions.search, (state) => ({ ...state, searching: true })),
on(NewMovieActions.searchCompleted, (state, search) => ({
...state,
searching: false,
searchResults: search.payload,
})),
on(NewMovieActions.addMovieToCollection, (state, action) => ({
...state,
newMovie: action.payload,
}))
);
export function reducer(state: State | undefined, action: Action) {
return newMovieReducer(state, action);
}