-
Notifications
You must be signed in to change notification settings - Fork 60
/
module.js
67 lines (63 loc) · 1.7 KB
/
module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
import * as type from './type';
import * as api from './api';
const mutations = {
[type.FETCH_MOVIES](state, payload) {
state.movies[payload.type].subjects =
state.movies[payload.type].subjects.concat(payload.subjects);
state.movies[payload.type].total = state.movies[payload.type].subjects.length;
},
[type.FETCH_MOVIES_QUERY](state, payload) {
state.movieQuery.subjects = state.movieQuery.subjects.concat(payload.subjects);
state.movieQuery.total = state.movies[payload.type].subjects.length;
},
[type.CLEAR_MOVIES_QUERY](state) {
state.movieQuery.total = 0;
state.movieQuery.subjects = [];
},
[type.FETCH_MOVIES_TAB](state, tab) {
state.tab = tab;
},
};
const actions = {
[type.FETCH_MOVIES](context, payload) {
api.fetchMovies(payload.type, { start: payload.start || 0 })
.then(data => context.commit(type.FETCH_MOVIES, {
type: payload.type,
subjects: data.subjects,
}));
},
[type.FETCH_MOVIES_QUERY](context, payload) {
api.fetchMoviesQuery(payload)
.then(data => context.commit(type.FETCH_MOVIES_QUERY, data));
},
[type.CLEAR_MOVIES_QUERY](context) {
context.commit(type.CLEAR_MOVIES_QUERY);
},
[type.FETCH_MOVIES_TAB](context, tab) {
context.commit(type.FETCH_MOVIES_TAB, tab);
},
};
export default {
state: {
movies: {
[api.MOVIESTYPE.inTheaters]: {
total: 0,
subjects: [],
describe: '',
},
[api.MOVIESTYPE.comingSoon]: {
total: 0,
subjects: [],
describe: '',
},
},
movieQuery: {
total: 0,
subjects: [],
describe: '',
},
tab: 'in_theaters',
},
mutations,
actions,
};