chore(svelte): cleanup init derived store
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
import CustomEdge from './CustomEdge.svelte';
|
import CustomEdge from './CustomEdge.svelte';
|
||||||
|
|
||||||
import '@xyflow/svelte/dist/style.css';
|
import '@xyflow/svelte/dist/style.css';
|
||||||
|
import InitTracker from './InitTracker.svelte';
|
||||||
|
|
||||||
const nodeTypes: NodeTypes = {
|
const nodeTypes: NodeTypes = {
|
||||||
custom: CustomNode,
|
custom: CustomNode,
|
||||||
@@ -148,6 +149,7 @@
|
|||||||
selectionMode={SelectionMode.Full}
|
selectionMode={SelectionMode.Full}
|
||||||
initialViewport={{ x: 100, y: 100, zoom: 2 }}
|
initialViewport={{ x: 100, y: 100, zoom: 2 }}
|
||||||
snapGrid={[25, 25]}
|
snapGrid={[25, 25]}
|
||||||
|
oninit={() => console.log('on init')}
|
||||||
on:nodeclick={(event) => console.log('on node click', event)}
|
on:nodeclick={(event) => console.log('on node click', event)}
|
||||||
on:nodemouseenter={(event) => console.log('on node enter', event)}
|
on:nodemouseenter={(event) => console.log('on node enter', event)}
|
||||||
on:nodemouseleave={(event) => console.log('on node leave', event)}
|
on:nodemouseleave={(event) => console.log('on node leave', event)}
|
||||||
@@ -207,6 +209,8 @@
|
|||||||
}}>hide/unhide</button
|
}}>hide/unhide</button
|
||||||
>
|
>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|
||||||
|
<InitTracker />
|
||||||
</SvelteFlow>
|
</SvelteFlow>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { useNodesInitialized, useInitialized } from '@xyflow/svelte';
|
||||||
|
|
||||||
|
const nodesInitialized = useNodesInitialized();
|
||||||
|
const initialized = useInitialized();
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (nodesInitialized) {
|
||||||
|
console.log('nodes initialized');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (initialized) {
|
||||||
|
console.log('initialized');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -359,28 +359,24 @@ export function createStore({
|
|||||||
([edges, defaultColor, id]) => createMarkerIds(edges, { defaultColor, id })
|
([edges, defaultColor, id]) => createMarkerIds(edges, { defaultColor, id })
|
||||||
),
|
),
|
||||||
initialized: (() => {
|
initialized: (() => {
|
||||||
console.log('This closure gets called');
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
const initialNodesLength = get(store.nodes).length;
|
const initialNodesLength = get(store.nodes).length;
|
||||||
const initialEdgesLength = get(store.edges).length;
|
const initialEdgesLength = get(store.edges).length;
|
||||||
return derived(
|
return derived(
|
||||||
[store.nodesInitialized, store.edgesInitialized, store.viewportInitialized],
|
[store.nodesInitialized, store.edgesInitialized, store.viewportInitialized],
|
||||||
([nodesInitialized, edgesInitialized, viewportInitialized]) => {
|
([nodesInitialized, edgesInitialized, viewportInitialized]) => {
|
||||||
console.log('Get the derived store even called?');
|
// If it was already initialized, return true from then on
|
||||||
// If it was already initialized once return true from then on
|
|
||||||
if (initialized) return initialized;
|
if (initialized) return initialized;
|
||||||
|
|
||||||
// if it hasn't been initialised check if is now
|
// if it hasn't been initialised check if it's now
|
||||||
if (initialNodesLength === 0) {
|
if (initialNodesLength === 0) {
|
||||||
initialized = viewportInitialized;
|
initialized = viewportInitialized;
|
||||||
return initialized;
|
} else if (initialEdgesLength === 0) {
|
||||||
}
|
|
||||||
if (initialEdgesLength === 0) {
|
|
||||||
initialized = viewportInitialized && nodesInitialized;
|
initialized = viewportInitialized && nodesInitialized;
|
||||||
return initialized;
|
} else {
|
||||||
|
initialized = viewportInitialized && nodesInitialized && edgesInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = viewportInitialized && nodesInitialized && edgesInitialized;
|
|
||||||
return initialized;
|
return initialized;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user