Просмотр исходного кода

:recycle: cleaning up vuex store

tags/0.9.0
J 4 лет назад
Родитель
Сommit
3c97df848a

+ 10
- 16
vue-theme/src/store/modules/event.js Просмотреть файл

@@ -6,37 +6,31 @@ const state = {
6 6
     singleEvent: null,
7 7
 }
8 8
 
9
+const now = new Date()
10
+
9 11
 const getters = {
10 12
     allEvents: state => state.all,
11 13
     allEventsLoaded: state => state.loaded,
12
-    pastEvents: state => {
13
-        const now = new Date()
14
-        return state.all.filter(event => {
15
-            return parseInt(event.end) > now
16
-        })
17
-    },
18
-    upcomingAndCurrentEvents: state => {
19
-        const now = new Date()
20
-        return state.all.filter(event => {
21
-            return parseInt(event.end) <= now
22
-        })
23
-    },
14
+    pastEvents: state => state.all.filter(event => parseInt(event.end) > now),
15
+    upcomingAndCurrentEvents: state.all.filter(event => parseInt(event.end) <= now),
24 16
 }
25 17
 
26 18
 const actions = {
27 19
     getAllEvents({ commit }, { sortType, params }) {
28 20
         commit('CLEAR_EVENTS')
29 21
         commit('EVENTS_LOADED', false)
30
-        return api.getByType({ type: 'event', sort: sortType, cb: events => {
22
+        const storeFetch = (events => {
31 23
             commit('STORE_FETCHED_EVENTS', { events })
32 24
             commit('EVENTS_LOADED', true)
33
-        }, params })
25
+        })
26
+        return api.getByType({ type: 'event', sort: sortType, params, cb: storeFetch })
34 27
     },
35 28
     getMoreEvents({ commit }, { sortType, params }) {
36
-        return api.getByType({ type: 'event', sort: sortType, cb: events => {
29
+        const storeFetch = (events => {
37 30
             commit('ADD_TO_FETCHED_EVENTS', { events })
38 31
             commit('EVENTS_LOADED', true)
39
-        }, params })
32
+        })
33
+        return api.getByType({ type: 'event', sort: sortType, params, cb: storeFetch })
40 34
     },
41 35
     getSingleEvent({ commit }, id) {
42 36
         commit('CLEAR_SINGLE_EVENTS')

+ 12
- 19
vue-theme/src/store/modules/exhibition.js Просмотреть файл

@@ -6,39 +6,32 @@ const state = {
6 6
     singleExhibition: null,
7 7
 }
8 8
 
9
+const now = new Date()
10
+
9 11
 const getters = {
10 12
     allExhibitions: state => state.all,
11 13
     allExhibitionsLoaded: state => state.loaded,
12
-    pastExhibitions: state => {
13
-        return state.all.filter(exhibition => {
14
-            const now = new Date()
15
-            return parseInt(exhibition.end) > now
16
-        })
17
-    },
18
-    upcomingAndCurrentExhibitions: state => {
19
-        return state.all
20
-        // return state.all.filter(exhibition => {
21
-        //     const now = new Date()
22
-        //     // return parseInt(exhibition.end) <= now
23
-        //     return parseInt(exhibition.end) <= now
24
-        // })
25
-    },
14
+    pastExhibitions: state => state.all.filter(exhibition => parseInt(exhibition.end) > now),
15
+    upcomingAndCurrentExhibitions: state => state.all,
16
+    // upcomingAndCurrentExhibitions: state => state.all.filter(exhibition => parseInt(exhibition.end) <= now)
26 17
 }
27 18
 
28 19
 const actions = {
29 20
     getAllExhibitions({ commit },{ sortType, params }) {
30 21
         commit('CLEAR_EXHIBITIONS')
31 22
         commit('EXHIBITIONS_LOADED', false)
32
-        return api.getByType({ type: 'exhibition', sort: sortType, cb: exhibitions => {
23
+        const storeFetch = (exhibitions => {
33 24
             commit('STORE_FETCHED_EXHIBITIONS', { exhibitions })
34 25
             commit('EXHIBITIONS_LOADED', true)
35
-        }, params })
26
+        })
27
+        return api.getByType({ type: 'exhibition', sort: sortType, params, cb: storeFetch })
36 28
     },
37
-    getMoreExhibitions({ commit },{ sortType, params }) {
38
-        return api.getByType({ type: 'exhibition', sort: sortType, cb: exhibitions => {
29
+    getMoreExhibitions({ commit }, { sortType, params }) {
30
+        const storeFetch = (exhibitions => {
39 31
             commit('ADD_TO_FETCHED_EXHIBITIONS', { exhibitions })
40 32
             commit('EXHIBITIONS_LOADED', true)
41
-        }, params })
33
+        })
34
+        return api.getByType({ type: 'exhibition', sort: sortType, params, cb: storeFetch })
42 35
     },
43 36
     getSingleExhibition({ commit }, id) {
44 37
         commit('CLEAR_SINGLE_EXHIBITIONS')

+ 6
- 4
vue-theme/src/store/modules/post.js Просмотреть файл

@@ -15,16 +15,18 @@ const actions = {
15 15
     getAllPosts({ commit }, { sortType, params }) {
16 16
         commit('CLEAR_POSTS')
17 17
         commit('POSTS_LOADED', false)
18
-        return api.getByType({ type: 'post', sort: sortType, cb: posts => {
18
+        const storeFetch = (posts => {
19 19
             commit('STORE_FETCHED_POSTS', { posts })
20 20
             commit('POSTS_LOADED', true)
21
-        }, params })
21
+        }) 
22
+        return api.getByType({ type: 'post', sort: sortType, params, cb: storeFetch)
22 23
     },
23 24
     getMorePosts({ commit }, { sortType, params }) {
24
-        return api.getByType({ type: 'post', sort: sortType, cb: posts => {
25
+        const storeFetch = (posts => {
25 26
             commit('ADD_TO_FETCHED_POSTS', { posts })
26 27
             commit('POSTS_LOADED', true)
27
-        }, params })
28
+        })
29
+        return api.getByType({ type: 'post', sort: sortType, params, cb: storeFetch })
28 30
     },
29 31
     getSinglePost({ commit }, id) {
30 32
         commit('CLEAR_SINGLE_POSTS')

Загрузка…
Отмена
Сохранить