Browse Source

:recycle: breaking up intersection callback

tags/0.9.0
J 4 years ago
parent
commit
8cdedc6da5
1 changed files with 16 additions and 10 deletions
  1. 16
    10
      vue-theme/src/pages/list.vue

+ 16
- 10
vue-theme/src/pages/list.vue View File

@@ -47,7 +47,7 @@ export default {
47 47
     data() {
48 48
         return {
49 49
             page: 0,
50
-            perPage: 9,
50
+            perPage: 18,
51 51
             keepFetching: true 
52 52
         }
53 53
     },
@@ -141,21 +141,27 @@ export default {
141 141
         },
142 142
         setIntersectionLoader() {
143 143
             if(!this.type) return console.error('cannot setup interseciton handler for undefined type')
144
-            
144
+
145 145
             console.warn('setting up intersection handler for:', this.type)
146 146
             const footerEl = document.querySelector(".footer-wrapper footer")
147 147
             console.warn('attach to: ',footerEl)
148 148
             if(!footerEl) return
149 149
 
150 150
             window.addEventListener("load", e => {
151
-                const observer = new IntersectionObserver(this.loadMorePosts, {
152
-                    rootMargin: "0px 0px -50px 0px",
151
+                const onIntersection = () => {
152
+                    console.log('intersected...')
153
+                    this.loadMorePosts()
154
+                    console.log('loaded morePosts...')
155
+                }
156
+                const observer = new IntersectionObserver(onIntersection, {
157
+                    rootMargin: "0px 0px -20px 0px",
153 158
                 })
154 159
                 observer.observe(footerEl)
155 160
             }, false)
156 161
         },
157
-        unsetIntersectionLoader() {
158
-            console.warn('unsetting intersection handler for:', this.type)
162
+        unsetIntersectionLoader(type) {
163
+            if(!type) return console.error('cannot unset intersection handler for undefined type...')
164
+            console.warn('unsetting intersection handler for:', type)
159 165
             window.removeEventListener("load", e => {}, false)
160 166
         },
161 167
         clearAndInitPostList() {
@@ -172,19 +178,19 @@ export default {
172 178
         // This only fires navigating from
173 179
         // a list page, to another list page
174 180
         type(newType, oldType){
181
+            this.unsetIntersectionLoader(oldType)
182
+            
175 183
             console.log('old:', oldType)
176 184
             console.log('new:', newType)
185
+            
177 186
             if(!postTypes.includes(newType)) return console.warn('type not found...')
178
-            this.clearAndInitPostList()
179 187
             this.setIntersectionLoader()
188
+            this.clearAndInitPostList()
180 189
         },
181 190
     },
182 191
     mounted() {
183 192
         this.clearAndInitPostList()
184 193
         this.setIntersectionLoader()
185
-    },
186
-    beforeUnmount() {
187
-        this.unsetIntersectionLoader()
188 194
     }
189 195
 }
190 196
 </script>

Loading…
Cancel
Save