reducers.tpl 3.35 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 11 12
    {{obj.NAME}}_HAS_ERROR,
    {{obj.NAME}}_IS_LOADING,
    {{obj.NAME}}_FETCH_DATA_SUCCESS,
Florent Chehab's avatar
Florent Chehab committed
13 14 15

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

    {% if 'read_only' not in obj or not obj.read_only %}
Florent Chehab's avatar
Florent Chehab committed
20 21
    {{obj.NAME}}_EL_IS_SAVING,
    {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
Florent Chehab's avatar
Florent Chehab committed
22
    {% endif %}
Florent Chehab's avatar
Florent Chehab committed
23

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

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
}

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

        default:
            return state;
    }
79 80
}

Florent Chehab's avatar
Florent Chehab committed
81 82 83 84


export function {{obj.name}}ElHasError(state = false, action) {
    switch (action.type) {
Florent Chehab's avatar
Florent Chehab committed
85
        case {{obj.NAME}}_EL_HAS_ERROR:
Florent Chehab's avatar
Florent Chehab committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
            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;
    }
}

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

        default:
            return state;
    }
}


{% if 'read_only' not in obj or not obj.read_only %}
// Handling POST and PUT


Florent Chehab's avatar
Florent Chehab committed
121 122 123 124 125 126 127 128 129 130
export function {{obj.name}}ElIsSaving(state = false, action) {
    switch (action.type) {
        case {{obj.NAME}}_EL_IS_SAVING:
            return action.isPosting;

        default:
            return state;
    }
}

131
export function {{obj.name}}ElSaved(state = { data: Object(), savedAt: null }, action) {
Florent Chehab's avatar
Florent Chehab committed
132 133 134
    switch (action.type) {
        case {{obj.NAME}}_EL_SAVING_DATA_SUCCESS:
            return {
135
                data: action.{{obj.name}}El,
Florent Chehab's avatar
Florent Chehab committed
136 137 138 139 140 141 142
                fetchedAt: action.{{obj.name}}ElSavedAt
            }

        default:
            return state;
    }
}
Florent Chehab's avatar
Florent Chehab committed
143
{% endif %}
Florent Chehab's avatar
Florent Chehab committed
144

145
{% endfor %}