reducers.tpl 3.8 KB
Newer Older
1
2
3
4
5
6
// WARNING
// THIS FILE HAS BEEN AUTOMATICALLY GENERATED
// WITH /frontend/generate/generate_frontend_files.js
// MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED 
// THIS WARNING DOESN'T APPLY TO .tpl FILES...

7
import {
8
{% for obj in data %}
Florent Chehab's avatar
Florent Chehab committed
9
    {{obj.NAME}}_INVALIDATED,
10
    {{obj.NAME}}_FETCH_HAS_ERROR,
11
12
    {{obj.NAME}}_IS_LOADING,
    {{obj.NAME}}_FETCH_DATA_SUCCESS,
Florent Chehab's avatar
Florent Chehab committed
13
14

    {{obj.NAME}}_EL_INVALIDATED,
15
    {{obj.NAME}}_EL_FETCH_HAS_ERROR,
Florent Chehab's avatar
Florent Chehab committed
16
17
18
    {{obj.NAME}}_EL_IS_LOADING,
    {{obj.NAME}}_EL_FETCH_DATA_SUCCESS,

Florent Chehab's avatar
Florent Chehab committed
19
    {% if not obj.read_only %}
Florent Chehab's avatar
Florent Chehab committed
20
    {{obj.NAME}}_EL_IS_SAVING,
21
    {{obj.NAME}}_EL_SAVING_HAS_ERROR,
22
    {{obj.NAME}}_EL_SHARE_SAVED_TIME,
Florent Chehab's avatar
Florent Chehab committed
23
    {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
Florent Chehab's avatar
Florent Chehab committed
24
    {% endif %}
Florent Chehab's avatar
Florent Chehab committed
25

26
{% endfor %}
27
28
} from "./action-types";

29
{% for obj in data %}
30
export function {{obj.name}}FetchHasError(state = {status: false, error: null}, action) {
31
    switch (action.type) {
32
33
34
35
36
        case {{obj.NAME}}_FETCH_HAS_ERROR:
            return {
                status: action.hasError,
                error: action.error
            }
37
38
39
40
41
42

        default:
            return state;
    }
}

43
export function {{obj.name}}IsLoading(state = false, action) {
44
    switch (action.type) {
45
        case {{obj.NAME}}_IS_LOADING:
46
47
48
49
50
51
52
            return action.isLoading;

        default:
            return state;
    }
}

53
export function {{obj.name}}Invalidated(state = false, action) {
54
    switch (action.type) {
55
        case {{obj.NAME}}_INVALIDATED:
56
57
58
59
60
61
62
            return action.invalidated;

        default:
            return state;
    }
}

Florent Chehab's avatar
Florent Chehab committed
63
64
65
66
67
68
69
70
71
72
export function {{obj.name}}ElIsLoading(state = false, action) {
    switch (action.type) {
        case {{obj.NAME}}_EL_IS_LOADING:
            return action.isLoading;

        default:
            return state;
    }
}

73
export function {{obj.name}}Fetched(state = { data: Object(), fetchedAt: null }, action) {
74
    switch (action.type) {
75
        case {{obj.NAME}}_FETCH_DATA_SUCCESS:
76
            return {
77
                data: action.{{obj.name}},
78
                fetchedAt: action.{{obj.name}}FetchedAt
79
80
81
82
83
            }

        default:
            return state;
    }
84
85
}

Florent Chehab's avatar
Florent Chehab committed
86
87


88
export function {{obj.name}}ElFetchHasError(state = {status: false, error: null}, action) {
Florent Chehab's avatar
Florent Chehab committed
89
    switch (action.type) {
90
91
92
93
94
        case {{obj.NAME}}_EL_FETCH_HAS_ERROR:
            return {
                status: action.hasError,
                error: action.error
            }
Florent Chehab's avatar
Florent Chehab committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
        default:
            return state;
    }
}

export function {{obj.name}}ElInvalidated(state = false, action) {
    switch (action.type) {
        case {{obj.NAME}}_EL_INVALIDATED:
            return action.invalidated;

        default:
            return state;
    }
}

110
export function {{obj.name}}ElFetched(state = { data: Object(), fetchedAt: null }, action) {
Florent Chehab's avatar
Florent Chehab committed
111
112
113
    switch (action.type) {
        case {{obj.NAME}}_EL_FETCH_DATA_SUCCESS:
            return {
114
                data: action.{{obj.name}}El,
Florent Chehab's avatar
Florent Chehab committed
115
116
117
118
119
120
121
122
123
                fetchedAt: action.{{obj.name}}ElFetchedAt
            }

        default:
            return state;
    }
}


Florent Chehab's avatar
Florent Chehab committed
124
{% if not obj.read_only %}
Florent Chehab's avatar
Florent Chehab committed
125
126
127
// Handling POST and PUT


Florent Chehab's avatar
Florent Chehab committed
128
129
130
export function {{obj.name}}ElIsSaving(state = false, action) {
    switch (action.type) {
        case {{obj.NAME}}_EL_IS_SAVING:
131
            return action.isSaving;
Florent Chehab's avatar
Florent Chehab committed
132
133
134
135
136
137

        default:
            return state;
    }
}

138

139
140
141
142
143
144
145
146
147
148
export function {{obj.name}}ElShareSavedTime(state = null, action) {
    switch (action.type) {
        case {{obj.NAME}}_EL_SHARE_SAVED_TIME:
            return action.time;

        default:
            return state;
    }
}

149
export function {{obj.name}}ElSavingHasError(state = {status: false, error: null}, action) {
Florent Chehab's avatar
Florent Chehab committed
150
    switch (action.type) {
151
        case {{obj.NAME}}_EL_SAVING_HAS_ERROR:
Florent Chehab's avatar
Florent Chehab committed
152
            return {
153
154
                status: action.hasError,
                error: action.error
Florent Chehab's avatar
Florent Chehab committed
155
156
157
158
159
160
            }

        default:
            return state;
    }
}
161

Florent Chehab's avatar
Florent Chehab committed
162
{% endif %}
Florent Chehab's avatar
Florent Chehab committed
163

164
{% endfor %}