Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
elements/file-list: only update when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed May 30, 2017
1 parent 0a0d031 commit 8ae5dc0
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions elements/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ var fileList = css`

module.exports = function () {
var component = microcomponent({
name: 'file-list'
name: 'file-list',
state: {
update: true
}
})
component.on('render', render)
component.on('update', update)
Expand All @@ -32,24 +35,31 @@ module.exports = function () {
function render () {
var { dat, onupdate } = this.props

if (!dat.files && dat.archive && dat.archive.on) {
dat.files = []
dat.archive.on('content', function () {
var fs = { name: '/', fs: dat.archive }
var progress = mirror(fs, '/', { dryRun: true })
progress.on('put', function (file) {
file.name = file.name.slice(1)
if (file.name === '') return
dat.files.push({
path: file.name,
stat: file.stat
})
dat.files.sort(function (a, b) {
return a.path.localeCompare(b.path)
if (dat) {
if (dat.files) {
this.state.update = false
} else {
if (dat.archive) {
dat.files = []
dat.archive.on('content', function () {
var fs = { name: '/', fs: dat.archive }
var progress = mirror(fs, '/', { dryRun: true })
progress.on('put', function (file) {
file.name = file.name.slice(1)
if (file.name === '') return
dat.files.push({
path: file.name,
stat: file.stat
})
dat.files.sort(function (a, b) {
return a.path.localeCompare(b.path)
})
component.state.update = true
onupdate()
})
})
onupdate()
})
})
}
}
}

return html`
Expand Down Expand Up @@ -84,7 +94,7 @@ module.exports = function () {
`
}

function update () {
return true
function update (props) {
return props.dat !== this.props.dat || this.state.update
}
}

0 comments on commit 8ae5dc0

Please sign in to comment.