-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4102d63
commit c98e8e0
Showing
2 changed files
with
15 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,11 +94,18 @@ This can help render `turbo-cable-stream-source` in Django template | |
|
||
`<turbo-cable-stream-source>` is a custom element provided by [turbo-rails](https://github.com/hotwired/turbo-rails/blob/097d8f90cf0c5ed24ac6b1a49cead73d49fa8ab5/app/javascript/turbo/cable_stream_source_element.js), with it, we can send Turbo Stream over the websocket connection and update the page in real time. | ||
|
||
```{note} | ||
1. To support Actioncable on the server, please install [django-actioncable](https://github.com/AccordBox/django-actioncable). | ||
2. Please import `<turbo-cable-stream-source>` in your JavaScript code. | ||
To import `turbo-cable-stream-source` element to the frontend, there are two ways: | ||
|
||
```html | ||
<script type="module"> | ||
import 'https://cdn.jsdelivr.net/npm/@hotwired/[email protected]/+esm' | ||
</script> | ||
``` | ||
|
||
Or you can [Jump start frontend project bundled by Webpack](https://github.com/AccordBox/python-webpack-boilerplate#jump-start-frontend-project-bundled-by-webpack) and install it via `npm install` | ||
|
||
After frontend work is done, to support Actioncable on the server, please install [django-actioncable](https://github.com/AccordBox/django-actioncable). | ||
|
||
In `routing.py`, register `TurboStreamCableChannel` | ||
|
||
```python | ||
|
@@ -111,6 +118,8 @@ cable_channel_register(TurboStreamCableChannel) | |
In Django template, we can subscribe to stream source like this: | ||
|
||
```html | ||
{% load turbo_helper %} | ||
|
||
{% turbo_stream_from 'chat' view.kwargs.chat_pk %} | ||
``` | ||
|
||
|
@@ -119,6 +128,8 @@ In Django template, we can subscribe to stream source like this: | |
Then in Python code, we can send Turbo Stream to the stream source like this | ||
|
||
```python | ||
from turbo_response.channel_helper import broadcast_render_to | ||
|
||
broadcast_render_to( | ||
["chat", instance.chat_id], | ||
template="message_append.turbo_stream.html", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters