Fix shared store

This commit is contained in:
Vadim
2021-01-24 22:15:19 +03:00
parent 57e177c88b
commit 3acceff7c3
3 changed files with 35 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
<script>
import { onDestroy, onMount, tick } from 'svelte'
import { store } from '../../store'
import { onMount, tick } from 'svelte'
import { createStore } from '../../store'
import Dots from '../Dots/Dots.svelte'
import Arrow from '../Arrow/Arrow.svelte'
import { NEXT, PREV } from '../../direction'
@@ -56,6 +56,7 @@
*/
export let dots = true
let store = createStore()
let currentPageIndex = 0
$: originalCurrentPageIndex = currentPageIndex - Number(infinite);
let pagesCount = 0
@@ -65,10 +66,6 @@
let pageWindowElement
let pagesElement
const unsubscribe = store.subscribe(value => {
currentPageIndex = value.currentPageIndex
})
function applyPageSizes() {
const children = pagesElement.children
pageWidth = pageWindowElement.clientWidth
@@ -107,6 +104,9 @@
onMount(async () => {
await tick()
const unsubscribe = store.subscribe(value => {
currentPageIndex = value.currentPageIndex
})
if (pagesElement && pageWindowElement) {
infinite && addClones()
applyPageSizes()
@@ -118,13 +118,10 @@
return () => {
removeResizeEventListener(applyPageSizes)
teardownAutoplay()
unsubscribe()
}
})
onDestroy(() => {
unsubscribe()
})
function handlePageChange(event) {
showPage(event.detail + Number(infinite), { offsetDelay: 0, animated: true })
}