[LocalLiveView] Documentation - #581
Conversation
d39dc51 to
0f6a098
Compare
0f6a098 to
ad3a5c2
Compare
a13cea8 to
f4b7e46
Compare
mat-hek
left a comment
There was a problem hiding this comment.
We also need to go through the modules: make sure that only the public ones are visible and that they're have up-to-date docs. Also, it seems that mix docs only generates docs for the server part. Not sure if it's in scope of this PR, but needs to be fixed before the release.
|
|
||
| - A Phoenix project generated with `mix phx.new` | ||
| - `:local_live_view` added as a dependency | ||
| - `pnpm` or `npm` for JS package management |
There was a problem hiding this comment.
IIRC pnpm works only from popcorn repo root, so a regular user needs npm
| Visit [localhost:4000](http://localhost:4000). The installer generated a sample `HelloLocal` view — add it to any template to confirm everything works: | ||
|
|
||
| ```heex | ||
| <.local_live_view view="HelloLocal" /> | ||
| ``` |
There was a problem hiding this comment.
Don't we generate a separate page that renders HelloLocal? If so, we can just tell the user to visit that page
|
|
||
| This should look familiar if you've used Phoenix LiveView. The differences are: | ||
|
|
||
| - `use LocalLiveView` instead of `use Phoenix.LiveView` |
There was a problem hiding this comment.
| - `use LocalLiveView` instead of `use Phoenix.LiveView` | |
| This should look familiar if you've used Phoenix LiveView. The only difference is `use LocalLiveView` instead of `use Phoenix.LiveView`. |
| ## Building and running | ||
|
|
||
| After adding the module, rebuild the WASM bundle: | ||
|
|
||
| ```bash | ||
| mix llv.build | ||
| ``` | ||
|
|
||
| Then start or reload the server: | ||
|
|
||
| ```bash | ||
| mix phx.server | ||
| ``` |
There was a problem hiding this comment.
This is rather unnecessary, since the watcher detects changes. Besides, we describe that in the previous chapter.
| ## Building and running | |
| After adding the module, rebuild the WASM bundle: | |
| ```bash | |
| mix llv.build | |
| ``` | |
| Then start or reload the server: | |
| ```bash | |
| mix phx.server | |
| ``` |
| └── mix.exs # Compiles to WASM via popcorn.cook | ||
| ``` | ||
|
|
||
| Add your LocalLiveView modules to `local/lib/`. They will be compiled into the WASM bundle when you run `mix llv.build`. |
There was a problem hiding this comment.
| Add your LocalLiveView modules to `local/lib/`. They will be compiled into the WASM bundle when you run `mix llv.build`. | |
| Now you can add your LocalLiveView modules to `local/lib/`. When the server is running, the LLV watcher detects changes and automatically rebuilds the local code. To enforce rebuild, run `mix llv.build` and restart the server. |
| <.local_live_view view="ThermostatLocal" /> | ||
| ``` | ||
|
|
||
| When mounting the same view multiple times, use the `id` attribute to give each instance a unique identifier. |
There was a problem hiding this comment.
This would fit better in the LocalLiveView module. I'd move it there. In this guide, you can add short comments inside the CounterLocal code, describing what each callback does in this particular case.
| ``` | ||
| Browser Server | ||
| ┌──────────────────────────────────────┐ ┌──────────────────┐ | ||
| │ Phoenix LiveView page │ │ Phoenix app │ | ||
| │ │ │ │ | ||
| │ <.local_live_view view="MyLocal"> │ │ Mirror.MyLocal │ | ||
| │ │ │ │ (optional) │ | ||
| │ ▼ │ │ ▲ │ | ||
| │ Popcorn (AtomVM WASM) │─────▶│ mirror_sync │ | ||
| │ MyLocal (your Elixir code) │ │ │ | ||
| │ ├── mount/3 │ └──────────────────┘ | ||
| │ ├── render/1 │ | ||
| │ └── handle_event/3 │ | ||
| └──────────────────────────────────────┘ | ||
| ``` |
There was a problem hiding this comment.
It would be nice to show on this picture that the server LV can render LLV, pass assigns to it and exchange events
| [ | ||
| # {:popcorn, "~> 0.3.0-rc2", targets: :wasm}, | ||
| {:popcorn, path: "../popcorn/elixir", targets: :wasm}, | ||
| {:popcorn, "~> 0.3.0-rc2", targets: :wasm}, |
There was a problem hiding this comment.
| {:popcorn, "~> 0.3.0-rc2", targets: :wasm}, | |
| {:popcorn, "~> 0.3.2", targets: :wasm}, |
| The source code for all examples is in the `examples/` directory of this repository: | ||
|
|
||
| - `local-lv-thermostat` — Basic state management and events | ||
| - `local-lv-forms` — Form handling with validation and Mirror Sync | ||
| - `local-lv-compare` — Side-by-side comparison of Phoenix LiveView vs LocalLiveView |
There was a problem hiding this comment.
let's add kanban and burrito
| | Phoenix LiveView | LocalLiveView | | ||
| |---|---| | ||
| | `use Phoenix.LiveView` | `use LocalLiveView` | | ||
| | `mount/3` | `mount/3` | | ||
| | `render/1` with `~H` | `render/1` with `~H` | | ||
| | `handle_event/3` | `handle_event/3` | | ||
| | `assign/2`, `update/3` | `assign/2`, `update/3` | | ||
| | `phx-click` | `phx-click` | | ||
| | Runs on server | Runs in browser (WASM) | |
There was a problem hiding this comment.
I'm not sure if presenting this as a table is the good approach, since both columns are almost the same, and to understand it, you need to carefully read through it.
cd local_live_viewandmix docsto generate documentation - then opendoc/index.htmlto read