reducers.tpl 3.54 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,
Florent Chehab's avatar
Florent Chehab committed
22
    {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
Florent Chehab's avatar
Florent Chehab committed
23
    {% endif %}
Florent Chehab's avatar
Florent Chehab committed
24

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

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
83
84
}

Florent Chehab's avatar
Florent Chehab committed
85
86


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

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

        default:
            return state;
    }
}


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


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

        default:
            return state;
    }
}

137
138

export function {{obj.name}}ElSavingHasError(state = {status: false, error: null}, action) {
Florent Chehab's avatar
Florent Chehab committed
139
    switch (action.type) {
140
        case {{obj.NAME}}_EL_SAVING_HAS_ERROR:
Florent Chehab's avatar
Florent Chehab committed
141
            return {
142
143
                status: action.hasError,
                error: action.error
Florent Chehab's avatar
Florent Chehab committed
144
145
146
147
148
149
            }

        default:
            return state;
    }
}
150

Florent Chehab's avatar
Florent Chehab committed
151
{% endif %}
Florent Chehab's avatar
Florent Chehab committed
152

153
{% endfor %}