Newer
Older
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { createReducer, on } from '@ngrx/store';
import * as detailActions from '../actions/detail.actions';
/**
* Interface for detail state.
*
* @interface State
*/
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
export interface State {
object: any;
objectIsLoading: boolean;
objectIsLoaded: boolean;
spectraCSV: string;
spectraIsLoading: boolean;
spectraIsLoaded: boolean;
}
export const initialState: State = {
object: null,
objectIsLoading: false,
objectIsLoaded: false,
spectraCSV: null,
spectraIsLoading: false,
spectraIsLoaded: false,
};
export const detailReducer = createReducer(
initialState,
on(detailActions.retrieveObject, state => ({
...state,
objectIsLoading: true,
objectIsLoaded: false
})),
on(detailActions.retrieveObjectSuccess, (state, { object }) => ({
...state,
objectIsLoading: false,
objectIsLoaded: true,
object
})),
on(detailActions.retrieveObjectFail, state => ({
...state,
objectIsLoading: false
})),
on(detailActions.retrieveSpectra, state => ({
...state,
spectraIsLoading: true,
spectraIsLoaded: false
})),
on(detailActions.retrieveSpectraSuccess, (state, { spectraCSV }) => ({
...state,
spectraIsLoading: false,
spectraIsLoaded: true,
spectraCSV
})),
on(detailActions.retrieveSpectraFail, state => ({
...state,
spectraIsLoading: false
}))
);
export const selectObject = (state: State) => state.object;
export const selectObjectIsLoading = (state: State) => state.objectIsLoading;
export const selectObjectIsLoaded = (state: State) => state.objectIsLoaded;
export const selectSpectraCSV = (state: State) => state.spectraCSV;
export const selectSpectraIsLoading = (state: State) => state.spectraIsLoading;
export const selectSpectraIsLoaded = (state: State) => state.spectraIsLoaded;