Skip to content

Instantly share code, notes, and snippets.

@t9md
Last active November 27, 2017 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t9md/704ff030ab8341dd5f3ad51d598228e4 to your computer and use it in GitHub Desktop.
Save t9md/704ff030ab8341dd5f3ad51d598228e4 to your computer and use it in GitHub Desktop.
renderItems () {
if (this.items.length > 0) {
const className = ['list-group'].concat(this.props.itemsClassList || []).join(' ')
if (this.observer) {
etch.getScheduler().getNextUpdatePromise().then(() => {
const elements = Array.from(this.refs.items.children)
// Use initially rendered last item's height as height of all fake item
// Refering 1st item is bad idea, since 1st item tend to be rendered differently.
// const heightForFakeItem = elements.slice(0, this.props.initialRenderItemCount).pop().offsetHeight + 'px'
const heightForFakeItem = elements.slice(0, this.props.initialRenderItemCount).pop().scrollHeight + 'px'
elements.slice(this.props.initialRenderItemCount).forEach(element => {
element.style.height = heightForFakeItem
this.observer.observe(element)
})
})
}
this.listItems = this.items.map((item, index) => {
const selected = this.getSelectedItem() === item
return $(ListItemView, {
element: this.elementForItem(item, {selected, index}),
selected: selected,
onclick: () => this.didClickItem(index)
})
})
return $.ol(
{className, ref: 'items'},
...this.listItems
)
} else if (!this.props.loadingMessage && this.props.emptyMessage) {
return $.span({ref: 'emptyMessage'}, this.props.emptyMessage)
} else {
return ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment