|
51 | 51 | var LEADING_BUFFER = 2; |
52 | 52 |
|
53 | 53 | var Virtual = /*#__PURE__*/function () { |
54 | | - function Virtual(param, updateHook) { |
| 54 | + function Virtual(param, callUpdate) { |
55 | 55 | _classCallCheck(this, Virtual); |
56 | 56 |
|
57 | | - this.init(param, updateHook); |
| 57 | + this.init(param, callUpdate); |
58 | 58 | } |
59 | 59 |
|
60 | 60 | _createClass(Virtual, [{ |
61 | 61 | key: "init", |
62 | | - value: function init(param, updateHook) { |
| 62 | + value: function init(param, callUpdate) { |
63 | 63 | // param data |
64 | 64 | this.param = param; |
65 | | - this.updateHook = updateHook; // size data |
| 65 | + this.callUpdate = callUpdate; // size data |
66 | 66 |
|
67 | 67 | this.sizes = new Map(); |
68 | 68 | this.firstRangeTotalSize = 0; |
|
76 | 76 |
|
77 | 77 | this.range = Object.create(null); |
78 | 78 |
|
79 | | - if (this.param) { |
| 79 | + if (param) { |
80 | 80 | this.checkRange(0, param.keeps - 1); |
81 | 81 | } // benchmark test data |
82 | 82 | // this.__bsearchCalls = 0 |
|
87 | 87 | key: "destroy", |
88 | 88 | value: function destroy() { |
89 | 89 | this.init(null, null); |
90 | | - } // return actually render range |
| 90 | + } // return current render range |
91 | 91 |
|
92 | 92 | }, { |
93 | 93 | key: "getRange", |
|
207 | 207 | } |
208 | 208 |
|
209 | 209 | this.checkRange(overs, this.getEndByStart(overs)); |
210 | | - } // return the pass overs at current scroll offset |
| 210 | + } // return the pass overs according to current scroll offset |
211 | 211 |
|
212 | 212 | }, { |
213 | 213 | key: "getScrollOvers", |
|
268 | 268 | this.lastCalcIndex = Math.max(this.lastCalcIndex, givenIndex - 1); |
269 | 269 | this.lastCalcIndex = Math.min(this.lastCalcIndex, this.getLastIndex()); |
270 | 270 | return offset; |
271 | | - } |
| 271 | + } // is fixed size type |
| 272 | + |
272 | 273 | }, { |
273 | 274 | key: "isFixedType", |
274 | 275 | value: function isFixedType() { |
|
279 | 280 | key: "getLastIndex", |
280 | 281 | value: function getLastIndex() { |
281 | 282 | return this.param.uniqueIds.length - 1; |
282 | | - } // in some conditions range will break, we need check and correct it |
| 283 | + } // in some conditions range is broke, we need correct it |
283 | 284 | // and then decide whether need update to next range |
284 | 285 |
|
285 | 286 | }, { |
|
299 | 300 | if (this.range.start !== start) { |
300 | 301 | this.updateRange(start, end); |
301 | 302 | } |
302 | | - } // call updating to a new range and rerender |
| 303 | + } // setting to a new range and rerender |
303 | 304 |
|
304 | 305 | }, { |
305 | 306 | key: "updateRange", |
|
308 | 309 | this.range.end = end; |
309 | 310 | this.range.padFront = this.getPadFront(); |
310 | 311 | this.range.padBehind = this.getPadBehind(); |
311 | | - this.updateHook(this.getRange()); |
312 | | - } // return end base on start when going to a new range |
| 312 | + this.callUpdate(this.getRange()); |
| 313 | + } // return end base on start |
313 | 314 |
|
314 | 315 | }, { |
315 | 316 | key: "getEndByStart", |
|
337 | 338 |
|
338 | 339 | if (this.isFixedType()) { |
339 | 340 | return (lastIndex - end) * this.fixedSizeValue; |
340 | | - } // if calculated all already, return the exactly offset |
| 341 | + } // if it's all calculated, return the exactly offset |
341 | 342 |
|
342 | 343 |
|
343 | 344 | if (this.lastCalcIndex === lastIndex) { |
|
346 | 347 | // if not, use a estimated value |
347 | 348 | return (lastIndex - end) * this.getEstimateSize(); |
348 | 349 | } |
349 | | - } // get estimate size for one item, get from param.size at first range |
| 350 | + } // get the item estimate size |
350 | 351 |
|
351 | 352 | }, { |
352 | 353 | key: "getEstimateSize", |
|
567 | 568 | // string value also use for aria role attribute |
568 | 569 | FOOTER: 'footer' |
569 | 570 | }; |
570 | | - var NAME = 'virtual-list'; |
571 | | - var VirtualList = Vue.component(NAME, { |
| 571 | + var VirtualList = Vue.component('virtual-list', { |
572 | 572 | props: VirtualProps, |
573 | 573 | data: function data() { |
574 | 574 | return { |
|
586 | 586 | created: function created() { |
587 | 587 | this.isHorizontal = this.direction === 'horizontal'; |
588 | 588 | this.directionKey = this.isHorizontal ? 'scrollLeft' : 'scrollTop'; |
589 | | - this.installVirtual(); // listen item size changing |
| 589 | + this.installVirtual(); // listen item size change |
590 | 590 |
|
591 | | - this.$on(EVENT_TYPE.ITEM, this.onItemResized); // listen slot size changing |
| 591 | + this.$on(EVENT_TYPE.ITEM, this.onItemResized); // listen slot size change |
592 | 592 |
|
593 | 593 | if (this.$slots.header || this.$slots.footer) { |
594 | 594 | this.$on(EVENT_TYPE.SLOT, this.onSlotResized); |
595 | 595 | } |
596 | 596 | }, |
597 | | - // set back offset when use keep-alive |
| 597 | + // set back offset when awake from keep-alive |
598 | 598 | activated: function activated() { |
599 | 599 | this.scrollToOffset(this.virtual.offset); |
600 | 600 | }, |
|
668 | 668 | uniqueIds: this.getUniqueIdFromDataSources() |
669 | 669 | }, this.onRangeChanged); // sync initial range |
670 | 670 |
|
671 | | - this.range = this.virtual.getRange(); // just for debug |
672 | | - // window.virtual = this.virtual |
| 671 | + this.range = this.virtual.getRange(); |
673 | 672 | }, |
674 | 673 | getUniqueIdFromDataSources: function getUniqueIdFromDataSources() { |
675 | 674 | var _this2 = this; |
|
683 | 682 | var root = this.$refs.root; |
684 | 683 | return root ? Math.ceil(root[this.directionKey]) : 0; |
685 | 684 | }, |
686 | | - // return client viewport size (width or height) |
| 685 | + // return client viewport size |
687 | 686 | getClientSize: function getClientSize() { |
688 | 687 | var root = this.$refs.root; |
689 | 688 | return root ? root[this.isHorizontal ? 'clientWidth' : 'clientHeight'] : 0; |
690 | 689 | }, |
691 | | - // return all scroll size (width or height) |
| 690 | + // return all scroll size |
692 | 691 | getScrollSize: function getScrollSize() { |
693 | 692 | var root = this.$refs.root; |
694 | 693 | return root ? root[this.isHorizontal ? 'scrollWidth' : 'scrollHeight'] : 0; |
|
738 | 737 | } |
739 | 738 | }, |
740 | 739 | // get the real render slots based on range data |
| 740 | + // in-place patch strategy will try to reuse components as possible |
| 741 | + // so those components that are reused will not trigger lifecycle mounted |
741 | 742 | getRenderSlots: function getRenderSlots(h) { |
742 | 743 | var slots = []; |
743 | | - var start = this.disabled ? 0 : this.range.start; |
744 | | - var end = this.disabled ? this.dataSources.length - 1 : this.range.end; |
| 744 | + var start = this.range.start; |
| 745 | + var end = this.range.end; |
745 | 746 |
|
746 | 747 | for (var index = start; index <= end; index++) { |
747 | 748 | var dataSource = this.dataSources[index]; |
|
760 | 761 | } |
761 | 762 | })); |
762 | 763 | } else { |
763 | | - console.warn("[".concat(NAME, "]: cannot get the index ").concat(index, " from data-sources.")); |
| 764 | + console.warn("Cannot get the index ".concat(index, " from data-sources.")); |
764 | 765 | } |
765 | 766 | } |
766 | 767 |
|
|
773 | 774 | var _this$$slots = this.$slots, |
774 | 775 | header = _this$$slots.header, |
775 | 776 | footer = _this$$slots.footer; |
776 | | - var padding = this.disabled ? 0 : this.isHorizontal ? "0px ".concat(this.range.padBehind, "px 0px ").concat(this.range.padFront, "px") : "".concat(this.range.padFront, "px 0px ").concat(this.range.padBehind, "px"); |
| 777 | + var padding = this.isHorizontal ? "0px ".concat(this.range.padBehind, "px 0px ").concat(this.range.padFront, "px") : "".concat(this.range.padFront, "px 0px ").concat(this.range.padBehind, "px"); |
777 | 778 | return h(this.rootTag, { |
778 | 779 | ref: 'root', |
779 | 780 | on: { |
|
0 commit comments