Skip to content

Commit bc19037

Browse files
committed
Version 2.1.2
1 parent 8cc27e2 commit bc19037

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

dist/index.js

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-virtual-scroll-list v2.1.1
2+
* vue-virtual-scroll-list v2.1.2
33
* open source under the MIT license
44
* https://github.com/tangbc/vue-virtual-scroll-list#readme
55
*/
@@ -427,6 +427,9 @@
427427
type: String,
428428
"default": ''
429429
},
430+
itemClassAdd: {
431+
type: Function
432+
},
430433
headerTag: {
431434
type: String,
432435
"default": 'div'
@@ -449,6 +452,9 @@
449452
}
450453
};
451454
var ItemProps = {
455+
index: {
456+
type: Number
457+
},
452458
event: {
453459
type: String
454460
},
@@ -492,27 +498,22 @@
492498
*/
493499
var Wrapper = {
494500
created: function created() {
495-
this.hasInitial = false;
496501
this.shapeKey = this.horizontal ? 'offsetWidth' : 'offsetHeight';
497502
},
498503
mounted: function mounted() {
499504
var _this = this;
500505

501-
// dispatch once at initial
502-
this.dispatchSizeChange();
503-
504506
if (typeof ResizeObserver !== 'undefined') {
505507
this.resizeObserver = new ResizeObserver(function () {
506-
// dispatch when size changed
507-
if (_this.hasInitial) {
508-
_this.dispatchSizeChange();
509-
} else {
510-
_this.hasInitial = true;
511-
}
508+
_this.dispatchSizeChange();
512509
});
513510
this.resizeObserver.observe(this.$el);
514511
}
515512
},
513+
// since componet will be reused, so disptach when updated
514+
updated: function updated() {
515+
this.dispatchSizeChange();
516+
},
516517
beforeDestroy: function beforeDestroy() {
517518
if (this.resizeObserver) {
518519
this.resizeObserver.disconnect();
@@ -537,8 +538,10 @@
537538
var tag = this.tag,
538539
component = this.component,
539540
_this$extraProps = this.extraProps,
540-
extraProps = _this$extraProps === void 0 ? {} : _this$extraProps;
541+
extraProps = _this$extraProps === void 0 ? {} : _this$extraProps,
542+
index = this.index;
541543
extraProps.source = this.source;
544+
extraProps.index = index;
542545
return h(tag, {
543546
role: 'item'
544547
}, [h(component, {
@@ -581,11 +584,9 @@
581584
};
582585
},
583586
watch: {
584-
dataSources: function dataSources(newValue, oldValue) {
585-
if (newValue.length !== oldValue.length) {
586-
this.virtual.updateParam('uniqueIds', this.getUniqueIdFromDataSources());
587-
this.virtual.handleDataSourcesChange();
588-
}
587+
'dataSources.length': function dataSourcesLength() {
588+
this.virtual.updateParam('uniqueIds', this.getUniqueIdFromDataSources());
589+
this.virtual.handleDataSourcesChange();
589590
},
590591
start: function start(newValue) {
591592
this.scrollToIndex(newValue);
@@ -621,6 +622,14 @@
621622
this.virtual.destroy();
622623
},
623624
methods: {
625+
// get item size by id
626+
getSize: function getSize(id) {
627+
return this.virtual.sizes.get(id);
628+
},
629+
// get the total number of stored (rendered) items
630+
getSizes: function getSizes() {
631+
return this.virtual.sizes.size;
632+
},
624633
// set current scroll position to a expectant offset
625634
scrollToOffset: function scrollToOffset(offset) {
626635
var root = this.$refs.root;
@@ -703,6 +712,7 @@
703712
// event called when each item mounted or size changed
704713
onItemResized: function onItemResized(id, size) {
705714
this.virtual.saveSize(id, size);
715+
this.$emit('resized', id, size);
706716
},
707717
// event called when slot mounted or size changed
708718
onSlotResized: function onSlotResized(type, size, hasInit) {
@@ -734,14 +744,12 @@
734744
},
735745
// emit event in special position
736746
emitEvent: function emitEvent(offset, clientSize, scrollSize, evt) {
737-
var range = this.virtual.getRange();
738-
739747
if (this.virtual.isFront() && !!this.dataSources.length && offset - this.topThreshold <= 0) {
740-
this.$emit('totop', evt, range);
748+
this.$emit('totop');
741749
} else if (this.virtual.isBehind() && offset + clientSize + this.bottomThreshold >= scrollSize) {
742-
this.$emit('tobottom', evt, range);
750+
this.$emit('tobottom');
743751
} else {
744-
this.$emit('scroll', evt, range);
752+
this.$emit('scroll', evt, this.virtual.getRange());
745753
}
746754
},
747755
// get the real render slots based on range data
@@ -766,16 +774,17 @@
766774
if (dataSource) {
767775
if (dataSource[dataKey]) {
768776
slots.push(h(Item, {
769-
"class": itemClass,
770777
props: {
778+
index: index,
771779
tag: itemTag,
772780
event: EVENT_TYPE.ITEM,
773781
horizontal: isHorizontal,
774782
uniqueKey: dataSource[dataKey],
775783
source: dataSource,
776784
extraProps: extraProps,
777785
component: dataComponent
778-
}
786+
},
787+
"class": "".concat(itemClass, " ").concat(this.itemClassAdd ? this.itemClassAdd(index) : '')
779788
}));
780789
} else {
781790
console.warn("Cannot get the data-key '".concat(dataKey, "' from data-sources."));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-virtual-scroll-list",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "A vue component support big amount data list with high scroll performance.",
55
"main": "dist/index.js",
66
"files": [

0 commit comments

Comments
 (0)