Commit 7f8b237
authored
Add onDocumentPatch callback and allow specifying event dispatch phase (#4043)
Relates to: https://elixirforum.com/t/extending-liveview-with-view-transition-api-support/73136
This commit adds a generic dom hook that runs before the view is patched:
```javascript
let liveSocket = new LiveSocket("/live", Socket, {
dom: {
onDocumentPatch(start) {
// do something
// then trigger the patch
start();
}
}
})
```
This can be used to call [document.startViewTransition](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition).
To be able to customize what kind of view transition to perform, this
commit also introduces a new optional fourth parameter on
`Phoenix.LiveView.push_event/3`. By default, events are only dispatched
after the view is patched, but sometimes it is useful to run some code
before patching the DOM:
```elixir
def mount(_params, _session, socket) do
{:ok,
socket
|> assign(...)
|> push_event("start-view-transition", %{type: "page"}, dispatch: :before)}
end
```
This event will be dispatched before performing the initial mount patch.1 parent 517afcb commit 7f8b237
File tree
4 files changed
+75
-8
lines changed- assets/js/phoenix_live_view
- lib
- phoenix_live_view
4 files changed
+75
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
149 | 170 | | |
150 | 171 | | |
151 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
320 | | - | |
321 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
322 | 349 | | |
323 | 350 | | |
324 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
779 | 779 | | |
780 | 780 | | |
781 | 781 | | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
782 | 791 | | |
783 | | - | |
| 792 | + | |
784 | 793 | | |
785 | 794 | | |
786 | 795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | | - | |
| 272 | + | |
| 273 | + | |
273 | 274 | | |
274 | | - | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
276 | 286 | | |
277 | 287 | | |
278 | 288 | | |
| |||
0 commit comments