Skip to content

Commit 283d8e1

Browse files
vincvdwalVincent van der WalFil
authored
Replace Svelte example with runes (v5.0.0+) and rm deprecated onmousemove (#2242)
* replace with runes and rm depr onmousemove * rm whitespace * readd whitespace in script tag * updated sandbox --------- Co-authored-by: Vincent van der Wal <[email protected]> Co-authored-by: Philippe Rivière <[email protected]>
1 parent b2b587a commit 283d8e1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/getting-started.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -302,29 +302,29 @@ Here’s an example of client-side rendering in Svelte. For server-side renderin
302302

303303
:::code-group
304304
```svelte [App.svelte]
305-
<script>
305+
<script lang="ts">
306306
import * as Plot from '@observablehq/plot';
307307
import * as d3 from 'd3';
308308
309-
let div;
310-
let data = d3.ticks(-2, 2, 200).map(Math.sin);
309+
let div: HTMLElement | undefined = $state();
310+
let data = $state(d3.ticks(-2, 2, 200).map(Math.sin));
311311
312-
function onMousemove(event) {
312+
function onMousemove(event: MouseEvent) {
313313
const [x, y] = d3.pointer(event);
314314
data = data.slice(-200).concat(Math.atan2(x, y));
315315
}
316316
317-
$: {
317+
$effect(() => {
318318
div?.firstChild?.remove(); // remove old chart, if any
319-
div?.append(Plot.lineY(data).plot({grid: true})); // add the new chart
320-
}
319+
div?.append(Plot.lineY(data).plot({ grid: true })); // add the new chart
320+
});
321321
</script>
322322
323-
<div on:mousemove={onMousemove} bind:this={div} role="img"></div>
323+
<div onmousemove={onMousemove} bind:this={div} role="img"></div>
324324
```
325325
:::
326326

327-
See our [Plot + Svelte REPL](https://svelte.dev/repl/ebf78a6a6c1145ecb84cf9345a7f82ae?version=4.2.0) for details.
327+
See our [Plot + Svelte REPL](https://svelte.dev/playground/e65b5c87ae7e44239cef41ec3df28f52?version=5.2.7) for details.
328328

329329
## Plot in Node.js
330330

0 commit comments

Comments
 (0)