Pārlūkot izejas kodu

:poop: movig getposts to inner definition

tags/0.9.0
J 4 gadus atpakaļ
vecāks
revīzija
6a6cc1e303
1 mainītis faili ar 16 papildinājumiem un 18 dzēšanām
  1. 16
    18
      vue-theme/src/pages/list.vue

+ 16
- 18
vue-theme/src/pages/list.vue Parādīt failu

87
     },
87
     },
88
     methods: {
88
     methods: {
89
         async loadMorePosts(shouldClear) {
89
         async loadMorePosts(shouldClear) {
90
-            if(shouldClear) this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
91
-            if(!this.keepFetching) return console.warn('nothing left to fetch...')
90
+            if(!this.keepFetching) return console.warn('Nothing left to fetch...')
91
+
92
+            const getPosts = async  (params, dispatchType) => {
93
+                if(!this.type) throw `post type: ${this.type} not found...`
94
+                console.log('$route :', this.$route)
95
+                // We always grab all pages on hero init so no need to do it here
96
+                return this.pType && this.type != 'page' ? await this.$store.dispatch(
97
+                    `get${dispatchType}${this.pType}`,
98
+                    { sortType: this.sortBy, params }
99
+                ) : []
100
+            }
92
 
101
 
102
+            if(shouldClear) this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
103
+            console.log('loadMore $route :', this.$route)
93
             try {
104
             try {
94
                 this.loadingFetched = true
105
                 this.loadingFetched = true
95
                 this.page++
106
                 this.page++
96
-                const res = await this.getPosts(
107
+                const res = await getPosts(
97
                     {
108
                     {
98
                         limit: this.shouldLoadAllAtOnce ? -1 : this.perPage,
109
                         limit: this.shouldLoadAllAtOnce ? -1 : this.perPage,
99
                         page: this.page
110
                         page: this.page
110
                 }
121
                 }
111
             } catch (err) { console.error(err) }
122
             } catch (err) { console.error(err) }
112
         },
123
         },
113
-        async getPosts(params, dispatchType) {
114
-            if(!this.type) throw `post type: ${this.type} not found...`
115
-            let res = []
116
-            console.log('$route :', this.$route)
117
-            // We always grab all pages on hero init so no need to do it here
118
-            if(this.pType && this.keepFetching && this.type != 'page') {
119
-                res = await this.$store.dispatch(
120
-                    `get${dispatchType}${this.pType}`,
121
-                    { sortType: this.sortBy, params }
122
-                )
123
-            }
124
-            return res
125
-        },
126
         async getPage(type) {
124
         async getPage(type) {
127
             await this._getAllIfNotLoaded('page', this.$store)
125
             await this._getAllIfNotLoaded('page', this.$store)
128
             if(!this.allPages) throw 'no pages in state'
126
             if(!this.allPages) throw 'no pages in state'
163
         unsetIntersectionLoader() {
161
         unsetIntersectionLoader() {
164
             const footerEl = document.querySelector(INTERSECT_SELECTOR)
162
             const footerEl = document.querySelector(INTERSECT_SELECTOR)
165
             try {
163
             try {
166
-                if(!footerEl) throw `cannot unset intersection handler missing el: ${footerEl}`
167
-                if(!this.observer) throw `cannot unset intersection handler missing observer: ${this.observer}`
164
+                if(!footerEl) throw `Cannot unset intersection handler missing el: ${footerEl}`
165
+                if(!this.observer) return 
168
                 this.observer.unobserve(footerEl)
166
                 this.observer.unobserve(footerEl)
169
                 this.observer.disconnect()
167
                 this.observer.disconnect()
170
             } catch (error) { console.error(error) }
168
             } catch (error) { console.error(error) }

Notiek ielāde…
Atcelt
Saglabāt