Skip to content

Commit e2d6e30

Browse files
committed
Bundle for development and production.
1 parent eeeb833 commit e2d6e30

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea
22
.vscode
33
dist/*.map
4+
dev
45
issues
56
node_modules

dist/index.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
},
109109
// tell parent current size identify by unqiue key.
110110
dispatchToParent: function dispatchToParent(event) {
111-
this.$parent.$emit.call(this.$parent, event, this.key, this.getCurrentSize());
111+
this.$parent.$emit(event, this.key, this.getCurrentSize());
112112
}
113113
},
114114
render: function render(h) {
@@ -221,6 +221,7 @@
221221

222222
this.__bsearchCalls = 0;
223223
this.__getIndexOffsetCalls = 0;
224+
this.__getIndexOffsetCacheHits = 0;
224225
}
225226
}, {
226227
key: "destroy",
@@ -314,20 +315,40 @@
314315
}
315316

316317
return low > 0 ? --low : 0;
317-
}
318+
} // return a scroll offset from given index.
319+
318320
}, {
319321
key: "getIndexOffset",
320-
value: function getIndexOffset(index) {
321-
// remember last calculate index.
322-
this.lastCalculatedIndex = Math.max(this.lastCalculatedIndex, index - 1);
323-
this.lastCalculatedIndex = Math.min(this.lastCalculatedIndex, this.getLastIndex());
324-
var offset = 0;
322+
value: function getIndexOffset(givenIndex) {
323+
// we know this!
324+
if (!givenIndex) {
325+
this.__getIndexOffsetCacheHits++;
326+
return 0;
327+
} // get from cache avoid too much calculate.
325328

326-
while (index--) {
327-
this.__getIndexOffsetCalls++;
328-
offset = offset + (this.sizes[this.param.uniqueIds[index]] || this.getEstimateSize());
329+
330+
if (givenIndex in this.offsetCaches) {
331+
this.__getIndexOffsetCacheHits++;
332+
return this.offsetCaches[givenIndex];
329333
}
330334

335+
var offset = 0;
336+
var indexOffset = 0;
337+
338+
for (var index = 0; index <= givenIndex; index++) {
339+
this.__getIndexOffsetCalls++; // cache last index index offset if exist.
340+
341+
if (index && indexOffset) {
342+
this.offsetCaches[index] = offset;
343+
}
344+
345+
indexOffset = this.sizes[this.param.uniqueIds[index]];
346+
offset = offset + (indexOffset || this.getEstimateSize());
347+
} // remember last calculate index.
348+
349+
350+
this.lastCalculatedIndex = Math.max(this.lastCalculatedIndex, givenIndex - 1);
351+
this.lastCalculatedIndex = Math.min(this.lastCalculatedIndex, this.getLastIndex());
331352
return offset;
332353
}
333354
}, {
@@ -466,4 +487,3 @@
466487
return VirtualList;
467488

468489
})));
469-
//# sourceMappingURL=index.js.map

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"scripts": {
1111
"lint": "eslint src --ext .js,.vue",
1212
"lint:fix": "eslint --fix src --ext .js,.vue",
13-
"build": "rollup --config ./scripts/rollup.config.js",
14-
"dev": "rollup --config ./scripts/rollup.config.js --watch"
13+
"build": "rollup --config ./scripts/rollup.production.js",
14+
"dev": "rollup --config ./scripts/rollup.development.js --watch"
1515
},
1616
"repository": {
1717
"type": "git",

scripts/rollup.development.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ProductionConfig from './rollup.production'
2+
3+
// development mode just rewrite from production config.
4+
export default Object.assign({}, ProductionConfig, {
5+
output: {
6+
...ProductionConfig.output,
7+
file: './dev/index.js',
8+
sourcemap: true,
9+
banner: null
10+
}
11+
})

scripts/rollup.config.js renamed to scripts/rollup.production.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export default {
88
format: 'umd',
99
file: './dist/index.js',
1010
name: 'VirtualList',
11-
// exports: 'named',
12-
sourcemap: true,
11+
sourcemap: false,
1312
globals: {
1413
vue: 'Vue',
1514
},

0 commit comments

Comments
 (0)