1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-14 03:05:41 +01:00
Pinafore-Web-Client-Frontend/routes/_components/list/List.html
greenkeeper[bot] 8dbc1b0503 Update standard to the latest version 🚀 (#519)
* chore(package): update standard to version 12.0.0

* package lock update

* fix eslint
2018-08-29 21:42:57 -07:00

65 lines
1.5 KiB
HTML

<div class="the-list" on:initialized>
{#each safeItems as item, i (item)}
<ListLazyItem
{component}
index={i}
{length}
{makeProps}
key={item}
on:initialized="itemInitialized()"
/>
{/each}
</div>
<style>
.the-list {
position: relative;
}
</style>
<script>
import ListLazyItem from './ListLazyItem.html'
import { listStore } from './listStore'
export default {
oncreate () {
let { realm } = this.get()
this.store.setCurrentRealm(realm)
},
ondestroy () {
this.store.setCurrentRealm(null)
},
methods: {
itemInitialized () {
let { initializedCount, length } = this.get()
initializedCount++
this.set({ initializedCount })
if (initializedCount === length) {
this.initialize()
}
},
initialize () {
let { scrollToItem } = this.get()
if (scrollToItem) {
let element = document.getElementById(`list-item-${scrollToItem}`)
requestAnimationFrame(() => {
console.log('scrolling element into view')
element.scrollIntoView(true)
this.fire('initialized')
})
} else {
this.fire('initialized')
}
}
},
data: () => ({
initializedCount: 0
}),
computed: {
safeItems: ({ items }) => items || [],
length: ({ safeItems }) => safeItems.length
},
components: {
ListLazyItem
},
store: () => listStore
}
</script>