You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/component-binding-deep-b/main.svelte

37 lines
889 B

<script>
import { beforeUpdate } from 'svelte';
import Editor from './Editor.svelte';
import ComponentSelector from './ComponentSelector.svelte';
export let components;
export let selectedComponent;
export let compiled;
let previouslySelectedComponent;
beforeUpdate(() => {
components.forEach(component => {
if (component === selectedComponent) return;
component.compiled = component.source.toUpperCase();
});
if (selectedComponent !== previouslySelectedComponent) {
selectedComponent.compiled = selectedComponent.source.toUpperCase();
updateBundle();
previouslySelectedComponent = selectedComponent;
}
});
function updateBundle() {
compiled = components.map(component => component.compiled).join('\n');
}
</script>
<ComponentSelector {components} bind:selectedComponent/>
<Editor bind:code={selectedComponent.source} />
<pre>
{compiled}
</pre>