chore(examples): cleanup

This commit is contained in:
moklick
2023-11-08 17:44:51 +01:00
parent e83079c5cd
commit d82a54fa5b
21 changed files with 700 additions and 557 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ declare global {
// interface Platform {}
}
interface GenericTestCase {
interface FlowConfig {
flowProps: Omit<SvelteFlowProps, 'nodes' | 'edges'> & { nodes: Node[]; edges: Edge[] };
}
}
@@ -158,4 +158,4 @@ export default {
// },
]
}
} satisfies GenericTestCase;
} satisfies FlowConfig;
@@ -88,4 +88,4 @@ export default {
}
]
}
} satisfies GenericTestCase;
} satisfies FlowConfig;
@@ -37,4 +37,4 @@ export default {
}
]
}
} satisfies GenericTestCase;
} satisfies FlowConfig;
@@ -34,4 +34,4 @@ export default {
}
]
}
} satisfies GenericTestCase;
} satisfies FlowConfig;
@@ -35,4 +35,4 @@ export default {
}
]
}
} satisfies GenericTestCase;
} satisfies FlowConfig;
@@ -3,9 +3,9 @@
import Flow from './Flow.svelte';
export let data;
export let data: { flowConfig: FlowConfig };
</script>
<SvelteFlowProvider>
<Flow generic={data.generic} />
<Flow flowConfig={data.flowConfig} />
</SvelteFlowProvider>
@@ -1,22 +1,19 @@
import { error } from '@sveltejs/kit';
const flowConfigs = import.meta.glob<FlowConfig>('/src/generic-tests/**/*.ts', {
eager: true,
import: 'default'
});
/** @type {import('./$types').PageLoad} */
export function load({ params }) {
try {
const genericTestCases = import.meta.glob<GenericTestCase>('/src/generic-tests/**/*.ts', {
eager: true,
import: 'default'
});
const flowConfig = flowConfigs[`/src/generic-tests/${params.topic}/${params.example}.ts`];
const generic = genericTestCases[`/src/generic-tests/${params.topic}/${params.example}.ts`];
if (generic) {
return {
generic
};
}
} catch (e) {
console.error(e);
if (!flowConfig) {
throw error(404, 'Not found');
}
throw error(404, 'Not found');
return {
flowConfig
};
}
@@ -4,13 +4,13 @@
import '@xyflow/svelte/dist/style.css';
export let generic: GenericTestCase;
export let flowConfig: FlowConfig;
// Create writables here so it is easier to create test cases
const nodes = writable(generic.flowProps.nodes);
const edges = writable(generic.flowProps.edges);
const nodes = writable(flowConfig.flowProps.nodes);
const edges = writable(flowConfig.flowProps.edges);
const svelteFlowPropsWithWritables = { ...generic.flowProps, nodes, edges };
const props = { ...flowConfig.flowProps, nodes, edges };
</script>
<SvelteFlow {...svelteFlowPropsWithWritables} />
<SvelteFlow {...props} />