11/**
2- * virtual list default component.
2+ * virtual list default component
33 */
44
55import Vue from 'vue'
@@ -12,7 +12,7 @@ const EVENT_TYPE = {
1212 SLOT : 'slot_resize'
1313}
1414const SLOT_TYPE = {
15- HEADER : 'header' , // string value also use for aria role attribute.
15+ HEADER : 'header' , // string value also use for aria role attribute
1616 FOOTER : 'footer'
1717}
1818
@@ -41,21 +41,21 @@ const VirtualList = Vue.component(NAME, {
4141 this . directionKey = this . isHorizontal ? 'scrollLeft' : 'scrollTop'
4242
4343 this . virtual = new Virtual ( {
44- size : this . size , // also could be a estimate value.
44+ size : this . size , // also could be a estimate value
4545 slotHeaderSize : 0 ,
4646 slotFooterSize : 0 ,
4747 keeps : this . keeps ,
48- buffer : Math . round ( this . keeps / 3 ) , // recommend for a third of keeps.
48+ buffer : Math . round ( this . keeps / 3 ) , // recommend for a third of keeps
4949 uniqueIds : this . getUniqueIdFromDataSources ( )
5050 } , this . onRangeChanged )
5151
52- // also need sync initial range first.
52+ // also need sync initial range first
5353 this . range = this . virtual . getRange ( )
5454
55- // listen item size changing.
55+ // listen item size changing
5656 this . $on ( EVENT_TYPE . ITEM , this . onItemResized )
5757
58- // listen slot size changing.
58+ // listen slot size changing
5959 if ( this . $slots . header || this . $slots . footer ) {
6060 this . $on ( EVENT_TYPE . SLOT , this . onSlotResized )
6161 }
@@ -66,7 +66,7 @@ const VirtualList = Vue.component(NAME, {
6666 } ,
6767
6868 mounted ( ) {
69- // set position.
69+ // set position
7070 if ( this . start ) {
7171 this . scrollToIndex ( this . start )
7272 } else if ( this . offset ) {
@@ -77,32 +77,32 @@ const VirtualList = Vue.component(NAME, {
7777 } ,
7878
7979 methods : {
80- // set current scroll position to a expectant offset.
80+ // set current scroll position to a expectant offset
8181 scrollToOffset ( offset ) {
8282 const { root } = this . $refs
8383 if ( root ) {
8484 root [ this . directionKey ] = offset || 0
8585 }
8686 } ,
8787
88- // set current scroll position to a expectant index.
88+ // set current scroll position to a expectant index
8989 scrollToIndex ( index ) {
9090 const offset = this . virtual . getOffset ( index )
9191 this . scrollToOffset ( offset )
9292 } ,
9393
94- // ----------- public method end. -----------
94+ // ----------- public method end -----------
9595
9696 getUniqueIdFromDataSources ( ) {
9797 return this . dataSources . map ( ( dataSource ) => dataSource [ this . dataKey ] )
9898 } ,
9999
100- // event called when every item mounted or size changed.
100+ // event called when each item mounted or size changed
101101 onItemResized ( id , size ) {
102102 this . virtual . saveSize ( id , size )
103103 } ,
104104
105- // event called when slot mounted or size changed.
105+ // event called when slot mounted or size changed
106106 onSlotResized ( type , size , hasInit ) {
107107 if ( type === SLOT_TYPE . HEADER ) {
108108 this . virtual . updateParam ( 'slotHeaderSize' , size )
@@ -115,7 +115,7 @@ const VirtualList = Vue.component(NAME, {
115115 }
116116 } ,
117117
118- // here is the rerendering entry.
118+ // here is the rerendering entry
119119 onRangeChanged ( range ) {
120120 this . range = range
121121 } ,
@@ -130,7 +130,7 @@ const VirtualList = Vue.component(NAME, {
130130 const offsetShape = root [ this . isHorizontal ? 'clientWidth' : 'clientHeight' ]
131131 const scrollShape = root [ this . isHorizontal ? 'scrollWidth' : 'scrollHeight' ]
132132
133- // iOS scrolling spring-back behavior will make direction mistake.
133+ // iOS scroll- spring-back behavior will make direction mistake
134134 if ( offset + offsetShape > scrollShape ) {
135135 return
136136 }
@@ -139,22 +139,19 @@ const VirtualList = Vue.component(NAME, {
139139 this . emitEvent ( offset , offsetShape , scrollShape , evt )
140140 } ,
141141
142- // emit event in special position.
142+ // emit event in special position
143143 emitEvent ( offset , offsetShape , scrollShape , evt ) {
144144 const range = this . virtual . getRange ( )
145- const isFront = this . virtual . isFront ( )
146- const isBehind = this . virtual . isBehind ( )
147-
148- if ( isFront && ! ! this . dataSources . length && offset - this . topThreshold <= 0 ) {
145+ if ( this . virtual . isFront ( ) && ! ! this . dataSources . length && offset - this . topThreshold <= 0 ) {
149146 this . $emit ( 'totop' , evt , range )
150- } else if ( isBehind && offset + offsetShape + this . bottomThreshold >= scrollShape ) {
147+ } else if ( this . virtual . isBehind ( ) && offset + offsetShape + this . bottomThreshold >= scrollShape ) {
151148 this . $emit ( 'tobottom' , evt , range )
152149 } else {
153150 this . $emit ( 'scroll' , evt , range )
154151 }
155152 } ,
156153
157- // get the real render slots based on range data.
154+ // get the real render slots based on range data
158155 getRenderSlots ( h ) {
159156 const slots = [ ]
160157 const start = this . disabled ? 0 : this . range . start
@@ -182,7 +179,7 @@ const VirtualList = Vue.component(NAME, {
182179 }
183180 } ,
184181
185- // render function, a closer-to-the-compiler alternative to templates.
182+ // render function, a closer-to-the-compiler alternative to templates
186183 // https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth
187184 render ( h ) {
188185 const { header, footer } = this . $slots
@@ -196,7 +193,7 @@ const VirtualList = Vue.component(NAME, {
196193 '&scroll' : this . onScroll
197194 }
198195 } , [
199- // header slot.
196+ // header slot
200197 header ? h ( Slot , {
201198 class : this . headerClass ,
202199 props : {
@@ -206,7 +203,7 @@ const VirtualList = Vue.component(NAME, {
206203 }
207204 } , header ) : null ,
208205
209- // main list.
206+ // main list
210207 h ( this . wrapTag , {
211208 class : this . wrapClass ,
212209 attrs : {
@@ -217,7 +214,7 @@ const VirtualList = Vue.component(NAME, {
217214 }
218215 } , this . getRenderSlots ( h ) ) ,
219216
220- // footer slot.
217+ // footer slot
221218 footer ? h ( Slot , {
222219 class : this . footerClass ,
223220 props : {
0 commit comments