Skip to content

Commit b48e881

Browse files
committed
expose IdomWebsocket via django_idom
1 parent 6a99175 commit b48e881

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ feel free to organize your component modules you wish. Any components created wi
3636
by Python dotted path in `your-template.html`.
3737

3838
```python
39-
import idom
39+
from idom import component, html
40+
from django_idom import IdomWebsocket
4041

41-
@idom.component
42-
def Hello(websocket, greeting_recipient): # Names are CamelCase by ReactJS convention
43-
return idom.html.header(f"Hello {greeting_recipient}!")
42+
43+
@component
44+
def Hello(websocket: IdomWebsocket, greeting_recipient): # Names are CamelCase by ReactJS convention
45+
return html.header(f"Hello {greeting_recipient}!")
4446
```
4547

4648
## `example_app/templates/your-template.html`

src/django_idom/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from .websocket.consumer import IdomWebsocket
12
from .websocket.paths import IDOM_WEBSOCKET_PATH
23

4+
35
__version__ = "0.0.1"
4-
__all__ = ["IDOM_WEBSOCKET_PATH"]
6+
__all__ = ["IDOM_WEBSOCKET_PATH", "IdomWebsocket"]

src/django_idom/websocket/consumer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
@dataclass
22-
class WebsocketConnection:
22+
class IdomWebsocket:
2323
scope: dict
2424
close: Callable[[Optional[int]], Awaitable[None]]
2525
disconnect: Callable[[int], Awaitable[None]]
@@ -67,7 +67,7 @@ async def _run_dispatch_loop(self):
6767
component_kwargs = json.loads(query_dict.get("kwargs", "{}"))
6868

6969
# Provide developer access to parts of this websocket
70-
socket = WebsocketConnection(self.scope, self.close, self.disconnect, view_id)
70+
socket = IdomWebsocket(self.scope, self.close, self.disconnect, view_id)
7171

7272
try:
7373
component_instance = component_constructor(socket, **component_kwargs)

0 commit comments

Comments
 (0)