Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jun 27, 2017
1 parent 9be92f5 commit 2992b77
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 50 deletions.
2 changes: 1 addition & 1 deletion dist/vue-virtual-scroller.js

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions docs-src/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default {
generateItems () {
console.log('Generating ' + this.count + ' items...')
let time = Date.now()
const items = Object.freeze(getData(this.count, this.enableLetters))
const items = getData(this.count, this.enableLetters)
this._time = Date.now()
this.generateTime = this._time - time
console.log('Generated ' + items.length + ' in ' + this.generateTime + 'ms')
Expand Down Expand Up @@ -207,12 +207,7 @@ body {
.letter {
text-transform: uppercase;
color: grey;
font-weight: lighter;
height: 200px;
}
.letter .value {
font-size: 120px;
font-weight: bold;
}
.index {
Expand Down
25 changes: 24 additions & 1 deletion docs-src/src/Letter.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<tr class="letter">
<tr class="letter" :class="{ big: big }" @click="toggle">
<td class="index">
{{item.index}}
</td>
Expand All @@ -12,5 +12,28 @@
<script>
export default {
props: ['item'],
computed: {
big () {
return this.item.height === 200
},
},
methods: {
toggle () {
this.item.height = this.big ? 42 : 200
},
},
}
</script>

<style scoped>
.letter.big {
font-weight: normal;
height: 200px;
}
.letter.big .value {
font-size: 120px;
}
</style>
50 changes: 25 additions & 25 deletions docs/build.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/build.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-virtual-scroller",
"description": "Smooth scrolling for any amount of data",
"version": "0.7.3",
"version": "0.7.5",
"author": {
"name": "Guillaume Chau",
"email": "[email protected]"
Expand Down
34 changes: 20 additions & 14 deletions src/components/VirtualScroller.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,30 @@ export default {
},
heights () {
const heights = {}
const items = this.items
const field = this.heightField
let accumulator = 0
for (let i = 0; i < items.length; i++) {
accumulator += items[i][field]
heights[i] = accumulator
if (this.itemHeight === null) {
const heights = {}
const items = this.items
const field = this.heightField
let accumulator = 0
for (let i = 0; i < items.length; i++) {
accumulator += items[i][field]
heights[i] = accumulator
}
return heights
}
return heights
},
},
watch: {
items () {
this.updateVisibleItems()
items: {
handler () {
this.updateVisibleItems(true)
},
deep: true,
},
pageMode () {
this.applyPageMode()
this.updateVisibleItems()
this.updateVisibleItems(true)
},
},
Expand Down Expand Up @@ -160,7 +165,7 @@ export default {
}
},
updateVisibleItems () {
updateVisibleItems (force = false) {
const l = this.items.length
const scroll = this.getScroll()
const items = this.items
Expand Down Expand Up @@ -224,10 +229,11 @@ export default {
containerHeight = l * itemHeight
}
if (startIndex !== this._startIndex || endIndex !== this._endIndex) {
if (force || startIndex !== this._startIndex || endIndex !== this._endIndex || l !== this._length) {
this.keysEnabled = !(startIndex > this._endIndex || endIndex < this._startIndex)
this._startIndex = startIndex
this._endIndex = endIndex
this._length = l
this.visibleItems = items.slice(startIndex, endIndex)
this.itemContainerStyle = {
height: containerHeight + 'px',
Expand Down Expand Up @@ -275,8 +281,8 @@ export default {
},
mounted () {
this.updateVisibleItems()
this.applyPageMode()
this.updateVisibleItems()
},
beforeDestroy () {
Expand Down

0 comments on commit 2992b77

Please sign in to comment.