Skip to content

Commit

Permalink
docs: Clean up transition to HMR in getting started (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt authored Aug 3, 2024
1 parent 29892fa commit e05a7d8
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions docs/src/pages/en/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,16 @@ export default { render }

As your widgets grow in complexity, it is recommended to separate your
front-end code from your Python code. Just move the `_esm` and `_css`
definitions to separate files and reference them via path.
(from above) to separate files and reference them via path.

```python
import pathlib
import anywidget
import traitlets

class CounterWidget(anywidget.AnyWidget):
_esm = pathlib.Path(__file__).parent / "index.js"
_css = pathlib.Path(__file__).parent / "index.css"
count = traitlets.Int(0).tag(sync=True)
_esm = "index.js"
_css = "index.css"
value = traitlets.Int(0).tag(sync=True)
```

This is both easier to read and allows you to use your favorite editor/IDE for your front-end code.
Expand All @@ -144,6 +143,20 @@ allowing real-time updates to your widget during development (below).
src="https://miro.medium.com/v2/resize:fit:1400/1*VCG-57YX8IrfTyeby3Ybjg.gif"
/>
> **Note**: Prefer `pathlib.Path` for file paths in production and outside
> notebooks to ensure OS compatibility and correct relative path resolution.
>
> ```py
> import pathlib
> import anywidget
> import traitlets
>
> class CounterWidget(anywidget.AnyWidget):
> _esm = pathlib.Path(__file__).parent / "index.js"
> _css = pathlib.Path(__file__).parent / "index.css"
> value = traitlets.Int(0).tag(sync=True)
> ```
## Watch & Learn
This video provides a detailed exploration of **anywidget** fundementals,
Expand Down

0 comments on commit e05a7d8

Please sign in to comment.