reducers.tpl 2.69 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
9
10
11
12
{% for obj in data %}
    {{obj.NAME}}_HAS_ERROR,
    {{obj.NAME}}_IS_LOADING,
    {{obj.NAME}}_FETCH_DATA_SUCCESS,
    {{obj.NAME}}_INVALIDATED,
Florent Chehab's avatar
Florent Chehab committed
13
14
15
16
17
18
19
20

    {{obj.NAME}}_EL_INVALIDATED,
    {{obj.NAME}}_EL_HAS_ERROR,
    {{obj.NAME}}_EL_IS_SAVING,
    {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
    {{obj.NAME}}_EL_IS_PUTTING,
    {{obj.NAME}}_EL_PUT_DATA_SUCCESS,

21
{% endfor %}
22
23
} from "./action-types";

24
25
{% for obj in data %}
export function {{obj.name}}HasError(state = false, action) {
26
    switch (action.type) {
27
        case {{obj.NAME}}_HAS_ERROR:
28
29
30
31
32
33
34
            return action.hasError;

        default:
            return state;
    }
}

35
export function {{obj.name}}IsLoading(state = false, action) {
36
    switch (action.type) {
37
        case {{obj.NAME}}_IS_LOADING:
38
39
40
41
42
43
44
            return action.isLoading;

        default:
            return state;
    }
}

45
export function {{obj.name}}Invalidated(state = false, action) {
46
    switch (action.type) {
47
        case {{obj.NAME}}_INVALIDATED:
48
49
50
51
52
53
54
            return action.invalidated;

        default:
            return state;
    }
}

55
export function {{obj.name}}Fetched(state = { {{obj.name}}: [], {{obj.name}}FetchedAt: null }, action) {
56
    switch (action.type) {
57
        case {{obj.NAME}}_FETCH_DATA_SUCCESS:
58
            return {
59
60
                {{obj.name}}: action.{{obj.name}},
                fetchedAt: action.{{obj.name}}FetchedAt
61
62
63
64
65
            }

        default:
            return state;
    }
66
67
}

Florent Chehab's avatar
Florent Chehab committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

// Handling POST and PUT

export function {{obj.name}}ElHasError(state = false, action) {
    switch (action.type) {
        case {{obj.NAME}}_El_HAS_ERROR:
            return action.hasError;

        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;
    }
}

export function {{obj.name}}ElIsSaving(state = false, action) {
    switch (action.type) {
        case {{obj.NAME}}_EL_IS_SAVING:
            return action.isPosting;

        default:
            return state;
    }
}

export function {{obj.name}}ElSaved(state = { {{obj.name}}El: [], {{obj.name}}ElSavedAt: null }, action) {
    switch (action.type) {
        case {{obj.NAME}}_EL_SAVING_DATA_SUCCESS:
            return {
                {{obj.name}}El: action.{{obj.name}}El,
                fetchedAt: action.{{obj.name}}ElSavedAt
            }

        default:
            return state;
    }
}

114
{% endfor %}