| 
									
										
										
										
											2018-01-17 00:13:36 -08:00
										 |  |  | <!-- TODO: setting height is hacky, just make this element the scroller --> | 
					
						
							| 
									
										
										
										
											2018-01-21 14:31:59 -08:00
										 |  |  | <div class="virtual-list {{shown ? '' : 'hidden'}}" style="height: {{$height}}px;"> | 
					
						
							| 
									
										
										
										
											2018-01-15 17:25:32 -08:00
										 |  |  |   {{#each $visibleItems as item @key}} | 
					
						
							| 
									
										
										
										
											2018-01-23 18:15:14 -08:00
										 |  |  |     <VirtualListLazyItem :component | 
					
						
							|  |  |  |                          offset="{{item.offset}}" | 
					
						
							|  |  |  |                          makeProps="{{makeProps}}" | 
					
						
							|  |  |  |                          key="{{item.key}}" | 
					
						
							|  |  |  |                          index="{{item.index}}" | 
					
						
							| 
									
										
										
										
											2018-01-21 16:07:11 -08:00
										 |  |  |     /> | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |   {{/each}} | 
					
						
							| 
									
										
										
										
											2018-01-21 16:07:11 -08:00
										 |  |  |   {{#if $showFooter}} | 
					
						
							|  |  |  |     <VirtualListFooter component="{{footerComponent}}"/> | 
					
						
							|  |  |  |   {{/if}} | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  | </div> | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  |   .virtual-list { | 
					
						
							|  |  |  |     position: relative; | 
					
						
							| 
									
										
										
										
											2018-01-21 14:31:59 -08:00
										 |  |  |     transition: opacity 0.25s linear; | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | <script> | 
					
						
							| 
									
										
										
										
											2018-01-23 18:15:14 -08:00
										 |  |  |   import VirtualListLazyItem from './VirtualListLazyItem' | 
					
						
							| 
									
										
										
										
											2018-01-21 16:07:11 -08:00
										 |  |  |   import VirtualListFooter from './VirtualListFooter.html' | 
					
						
							| 
									
										
										
										
											2018-01-15 12:23:28 -08:00
										 |  |  |   import { virtualListStore } from '../_utils/virtualListStore' | 
					
						
							| 
									
										
										
										
											2018-01-18 21:52:58 -08:00
										 |  |  |   import throttle from 'lodash/throttle' | 
					
						
							| 
									
										
										
										
											2018-01-17 00:59:15 -08:00
										 |  |  |   import { mark, stop } from '../_utils/marks' | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-18 21:52:58 -08:00
										 |  |  |   const DISTANCE_FROM_BOTTOM_TO_FIRE = 400 | 
					
						
							|  |  |  |   const SCROLL_TO_BOTTOM_DELAY = 1000 | 
					
						
							| 
									
										
										
										
											2018-01-15 17:25:32 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |   export default { | 
					
						
							| 
									
										
										
										
											2018-01-15 17:25:32 -08:00
										 |  |  |     oncreate () { | 
					
						
							| 
									
										
										
										
											2018-01-21 16:07:11 -08:00
										 |  |  |       this.observe('showFooter', showFooter => { | 
					
						
							|  |  |  |         this.store.set({showFooter: showFooter}) | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-01-15 12:23:28 -08:00
										 |  |  |       this.observe('items', (items) => { | 
					
						
							| 
									
										
										
										
											2018-01-17 00:59:15 -08:00
										 |  |  |         mark('set items') | 
					
						
							| 
									
										
										
										
											2018-01-15 16:12:07 -08:00
										 |  |  |         this.store.set({ | 
					
						
							| 
									
										
										
										
											2018-01-16 23:16:15 -08:00
										 |  |  |           items: items | 
					
						
							| 
									
										
										
										
											2018-01-15 16:12:07 -08:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-01-17 00:59:15 -08:00
										 |  |  |         stop('set items') | 
					
						
							| 
									
										
										
										
											2018-01-18 21:52:58 -08:00
										 |  |  |         this.fireScrollToBottom = throttle(() => { | 
					
						
							|  |  |  |           this.fire('scrollToBottom') | 
					
						
							|  |  |  |         }, SCROLL_TO_BOTTOM_DELAY) | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-01-16 23:16:15 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-17 00:06:24 -08:00
										 |  |  |       let observedOnce = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-16 23:16:15 -08:00
										 |  |  |       this.observe('distanceFromBottom', (distanceFromBottom) => { | 
					
						
							| 
									
										
										
										
											2018-01-17 00:06:24 -08:00
										 |  |  |         if (!observedOnce) { | 
					
						
							|  |  |  |           observedOnce = true // TODO: the first time is always 0... need better way to handle this | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (distanceFromBottom >= 0 && | 
					
						
							| 
									
										
										
										
											2018-01-16 21:43:31 -08:00
										 |  |  |             distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) { | 
					
						
							| 
									
										
										
										
											2018-01-18 21:52:58 -08:00
										 |  |  |           this.fireScrollToBottom() | 
					
						
							| 
									
										
										
										
											2018-01-16 21:43:31 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-01-15 18:29:28 -08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |     data: () => ({ | 
					
						
							| 
									
										
										
										
											2018-01-15 12:23:28 -08:00
										 |  |  |       component: null | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2018-01-15 12:23:28 -08:00
										 |  |  |     store: () => virtualListStore, | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |     components: { | 
					
						
							| 
									
										
										
										
											2018-01-23 18:15:14 -08:00
										 |  |  |       VirtualListLazyItem, | 
					
						
							| 
									
										
										
										
											2018-01-21 16:07:11 -08:00
										 |  |  |       VirtualListFooter | 
					
						
							| 
									
										
										
										
											2018-01-16 23:16:15 -08:00
										 |  |  |     }, | 
					
						
							|  |  |  |     computed: { | 
					
						
							|  |  |  |       distanceFromBottom: ($scrollHeight, $scrollTop, $offsetHeight) => { | 
					
						
							|  |  |  |         return $scrollHeight - $scrollTop - $offsetHeight | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-01-15 10:54:02 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | </script> |