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