// App.svelte
<table>
<thead>
….
</thead>
<tbody>
{#each processes as process, index (
process.PID)}
<tr>
…
<td>
<button on:click={() => startStop(process)}>
{process.started ? ‘Stop’ : ‘Start’}
</button>
</td>
</tr>
{/each}
</tbody>
</table>
<script>
import { onMount } from ‘svelte’;
import { fetchProcesses, startProcess, stopProcess } from ‘….’;
let processes = [];
onMount(() => {
const timeout = setTimeout(async () => {
processes = await fetchProcesses();
}, 5000);
return () => clearTimeout(timeout);
});
function startStop(process) {
process.started ? stopProcess() : startProcess();
}
</script>