Skip to content

Commit b302981

Browse files
author
Guillaume Chau
committed
chore: v1.0.0-beta.5
1 parent 8b665c4 commit b302981

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed

dist/vue-virtual-scroller.esm.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,10 +1162,18 @@ var DynamicScroller = { render: function render() {
11621162
for (var i = 0; i < items.length; i++) {
11631163
var item = items[i];
11641164
var id = item[keyField];
1165+
var height = heights[id];
1166+
if (typeof height === 'undefined' && !this.$_undefinedMap[id]) {
1167+
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
1168+
this.$_undefinedHeights++;
1169+
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
1170+
this.$_undefinedMap[id] = true;
1171+
height = 0;
1172+
}
11651173
result.push({
11661174
item: item,
11671175
id: id,
1168-
height: heights[id] || 0
1176+
height: height
11691177
});
11701178
}
11711179
return result;
@@ -1182,11 +1190,15 @@ var DynamicScroller = { render: function render() {
11821190
},
11831191

11841192
watch: {
1185-
items: 'forceUpdate'
1193+
items: function items() {
1194+
this.forceUpdate(false);
1195+
}
11861196
},
11871197

11881198
created: function created() {
11891199
this.$_updates = [];
1200+
this.$_undefinedHeights = 0;
1201+
this.$_undefinedMap = {};
11901202
},
11911203
mounted: function mounted() {
11921204
var scroller = this.$refs.scroller;
@@ -1214,7 +1226,9 @@ var DynamicScroller = { render: function render() {
12141226
this.$emit('visible');
12151227
},
12161228
forceUpdate: function forceUpdate() {
1217-
this.vscrollData.heights = {};
1229+
var clear = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1230+
1231+
if (clear) this.vscrollData.heights = {};
12181232
this.$emit('vscroll:update', { force: true });
12191233
},
12201234
getSize: function getSize(scroller) {
@@ -1223,6 +1237,30 @@ var DynamicScroller = { render: function render() {
12231237
scrollToItem: function scrollToItem(index) {
12241238
var scroller = this.$refs.scroller;
12251239
if (scroller) scroller.scrollToItem(index);
1240+
},
1241+
getItemSize: function getItemSize(item) {
1242+
var id = item[this.keyField];
1243+
return this.vscrollData.heights[id] || 0;
1244+
},
1245+
scrollToBottom: function scrollToBottom() {
1246+
var _this = this;
1247+
1248+
if (this.$_scrollingToBottom) return;
1249+
this.$_scrollingToBottom = true;
1250+
var el = this.$el;
1251+
// Item is inserted to the DOM
1252+
this.$nextTick(function () {
1253+
// Item sizes are computed
1254+
var cb = function cb() {
1255+
el.scrollTop = el.scrollHeight;
1256+
if (_this.$_undefinedHeights === 0) {
1257+
_this.$_scrollingToBottom = false;
1258+
} else {
1259+
requestAnimationFrame(cb);
1260+
}
1261+
};
1262+
requestAnimationFrame(cb);
1263+
});
12261264
}
12271265
}
12281266
};
@@ -1372,6 +1410,10 @@ var DynamicScrollerItem = {
13721410
if (_this3.id === id) {
13731411
var size = _this3.getSize();
13741412
if (size.height && _this3.height !== size.height) {
1413+
if (_this3.vscrollBus.$_undefinedMap[id]) {
1414+
_this3.vscrollBus.$_undefinedHeights--;
1415+
_this3.vscrollBus.$_undefinedMap[id] = undefined;
1416+
}
13751417
_this3.$set(_this3.vscrollData.heights, _this3.id, size.height);
13761418
if (_this3.emitResize) _this3.$emit('resize', _this3.id);
13771419
}
@@ -1488,7 +1530,7 @@ function registerComponents(Vue$$1, prefix) {
14881530

14891531
var plugin = {
14901532
// eslint-disable-next-line no-undef
1491-
version: "1.0.0-beta.4",
1533+
version: "1.0.0-beta.5",
14921534
install: function install(Vue$$1, options) {
14931535
var finalOptions = Object.assign({}, {
14941536
installComponents: true,

0 commit comments

Comments
 (0)