Fix shared store
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onDestroy, onMount, tick } from 'svelte'
|
import { onMount, tick } from 'svelte'
|
||||||
import { store } from '../../store'
|
import { createStore } from '../../store'
|
||||||
import Dots from '../Dots/Dots.svelte'
|
import Dots from '../Dots/Dots.svelte'
|
||||||
import Arrow from '../Arrow/Arrow.svelte'
|
import Arrow from '../Arrow/Arrow.svelte'
|
||||||
import { NEXT, PREV } from '../../direction'
|
import { NEXT, PREV } from '../../direction'
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
*/
|
*/
|
||||||
export let dots = true
|
export let dots = true
|
||||||
|
|
||||||
|
let store = createStore()
|
||||||
let currentPageIndex = 0
|
let currentPageIndex = 0
|
||||||
$: originalCurrentPageIndex = currentPageIndex - Number(infinite);
|
$: originalCurrentPageIndex = currentPageIndex - Number(infinite);
|
||||||
let pagesCount = 0
|
let pagesCount = 0
|
||||||
@@ -65,10 +66,6 @@
|
|||||||
let pageWindowElement
|
let pageWindowElement
|
||||||
let pagesElement
|
let pagesElement
|
||||||
|
|
||||||
const unsubscribe = store.subscribe(value => {
|
|
||||||
currentPageIndex = value.currentPageIndex
|
|
||||||
})
|
|
||||||
|
|
||||||
function applyPageSizes() {
|
function applyPageSizes() {
|
||||||
const children = pagesElement.children
|
const children = pagesElement.children
|
||||||
pageWidth = pageWindowElement.clientWidth
|
pageWidth = pageWindowElement.clientWidth
|
||||||
@@ -107,6 +104,9 @@
|
|||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await tick()
|
await tick()
|
||||||
|
const unsubscribe = store.subscribe(value => {
|
||||||
|
currentPageIndex = value.currentPageIndex
|
||||||
|
})
|
||||||
if (pagesElement && pageWindowElement) {
|
if (pagesElement && pageWindowElement) {
|
||||||
infinite && addClones()
|
infinite && addClones()
|
||||||
applyPageSizes()
|
applyPageSizes()
|
||||||
@@ -118,13 +118,10 @@
|
|||||||
return () => {
|
return () => {
|
||||||
removeResizeEventListener(applyPageSizes)
|
removeResizeEventListener(applyPageSizes)
|
||||||
teardownAutoplay()
|
teardownAutoplay()
|
||||||
|
unsubscribe()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onDestroy(() => {
|
|
||||||
unsubscribe()
|
|
||||||
})
|
|
||||||
|
|
||||||
function handlePageChange(event) {
|
function handlePageChange(event) {
|
||||||
showPage(event.detail + Number(infinite), { offsetDelay: 0, animated: true })
|
showPage(event.detail + Number(infinite), { offsetDelay: 0, animated: true })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,12 @@
|
|||||||
{ color: '#19c97d', text: '8' },
|
{ color: '#19c97d', text: '8' },
|
||||||
{ color: '#00c36f', text: '9' }
|
{ color: '#00c36f', text: '9' }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const colors2 = [
|
||||||
|
{ color: '#e5f9f0', text: '0' },
|
||||||
|
{ color: '#ccf3e2', text: '1' },
|
||||||
|
{ color: '#b2edd3', text: '2' }
|
||||||
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="main-container">
|
<div class="main-container">
|
||||||
@@ -76,11 +82,32 @@
|
|||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</Carousel>
|
</Carousel>
|
||||||
|
|
||||||
|
<Carousel
|
||||||
|
{arrows}
|
||||||
|
{infinite}
|
||||||
|
{initialPageIndex}
|
||||||
|
{speed}
|
||||||
|
{autoplay}
|
||||||
|
{autoplaySpeed}
|
||||||
|
{autoplayDirection}
|
||||||
|
{dots}
|
||||||
|
>
|
||||||
|
{#each colors2 as { color, text } (color)}
|
||||||
|
<div
|
||||||
|
class="color-container"
|
||||||
|
style="background-color: {color};"
|
||||||
|
>
|
||||||
|
<p>{text}</p>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</Carousel>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.main-container {
|
.main-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.color-container {
|
.color-container {
|
||||||
|
|||||||
@@ -61,4 +61,4 @@ function createStore() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const store = createStore();
|
export { createStore };
|
||||||
|
|||||||
Reference in New Issue
Block a user