You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support for non-serializable component parameters (#120)
- Database backed component parameters
- The `component` template tag now supports both positional and keyword arguments.
- The `component` template tag now supports non-serializable arguments.
- It is now mandatory to run `manage.py migrate` after installing IDOM
- `IDOM_WS_MAX_RECONNECT_TIMEOUT` has been renamed to `IDOM_RECONNECT_MAX` and is now used as the default timeout for component parameters
- Bumped the minimum IDOM version to 0.43.0
- `idom.backend.hooks` support.
- `django_idom.types.IdomWebsocket` has been renamed to `Connection` and modified to fit the new schema
- `view_to_component` utility will now automatically use `del_html_head_body_transform`
- Set `IDOM_DEBUG_MODE` to `settings.py:DEBUG`
- The react client is now set to production rather than development
- Make a harmless utils public but undocumented
- Documentation for `django_query_postprocessor`
In your **Django app**'s HTML template, you can now embed your IDOM component using the `component` template tag. Within this tag, you will need to type in your dotted path to the component function as the first argument.
48
48
49
-
Additionally, you can pass in keyword arguments into your component function. For example, after reading the code below, pay attention to how the function definition for `hello_world` (_in the previous example_) accepts a `recipient` argument.
49
+
Additionally, you can pass in `args` and `kwargs` into your component function. For example, after reading the code below, pay attention to how the function definition for `hello_world` (_in the previous example_) accepts a `recipient` argument.
Copy file name to clipboardExpand all lines: docs/src/features/decorators.md
+1-7
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,16 @@
4
4
5
5
## Auth Required
6
6
7
-
You can limit access to a component to users with a specific `auth_attribute` by using this decorator.
7
+
You can limit access to a component to users with a specific `auth_attribute` by using this decorator (with or without parentheses).
8
8
9
9
By default, this decorator checks if the user is logged in, and his/her account has not been deactivated.
10
10
11
11
This decorator is commonly used to selectively render a component only if a user [`is_staff`](https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.User.is_staff) or [`is_superuser`](https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.User.is_superuser).
12
12
13
-
This decorator can be used with or without parentheses.
14
-
15
13
=== "components.py"
16
14
17
15
```python
18
16
from django_idom.decorators import auth_required
19
-
from django_idom.hooks import use_websocket
20
17
from idom import component, html
21
18
22
19
@component
@@ -70,7 +67,6 @@ This decorator can be used with or without parentheses.
70
67
71
68
```python
72
69
from django_idom.decorators import auth_required
73
-
from django_idom.hooks import use_websocket
74
70
from idom import component, html
75
71
76
72
@component
@@ -87,7 +83,6 @@ This decorator can be used with or without parentheses.
87
83
88
84
```python
89
85
from django_idom.decorators import auth_required
90
-
from django_idom.hooks import use_websocket
91
86
from idom import component, html
92
87
93
88
@@ -120,7 +115,6 @@ This decorator can be used with or without parentheses.
This is a shortcut that returns the Websocket's `origin`.
403
405
404
-
You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en/stable/topics/consumers.html#asyncjsonwebsocketconsumer) at any time by using `use_websocket`.
406
+
You can expect this hook to provide strings such as `http://example.com`.
405
407
406
408
=== "components.py"
407
409
408
410
```python
409
411
from idom import component, html
410
-
from django_idom.hooks import use_websocket
412
+
from django_idom.hooks import use_origin
411
413
412
414
@component
413
415
def my_component():
414
-
my_websocket = use_websocket()
415
-
return html.div(my_websocket)
416
+
my_origin = use_origin()
417
+
return html.div(my_origin)
416
418
```
417
419
418
420
??? example "See Interface"
@@ -425,22 +427,22 @@ You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en
425
427
426
428
| Type | Description |
427
429
| --- | --- |
428
-
| `IdomWebsocket` | The component's websocket. |
430
+
| `str | None` | A string containing the browser's current origin, obtained from websocket headers (if available). |
429
431
430
-
## Use Scope
432
+
## Use Connection
431
433
432
-
This is a shortcut that returns the Websocket's [`scope`](https://channels.readthedocs.io/en/stable/topics/consumers.html#scope).
434
+
You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en/stable/topics/consumers.html#asyncjsonwebsocketconsumer) at any time by using `use_connection`.
433
435
434
436
=== "components.py"
435
437
436
438
```python
437
439
from idom import component, html
438
-
from django_idom.hooks import use_scope
440
+
from django_idom.hooks import use_connection
439
441
440
442
@component
441
443
def my_component():
442
-
my_scope = use_scope()
443
-
return html.div(my_scope)
444
+
my_connection = use_connection()
445
+
return html.div(my_connection)
444
446
```
445
447
446
448
??? example "See Interface"
@@ -453,24 +455,22 @@ This is a shortcut that returns the Websocket's [`scope`](https://channels.readt
453
455
454
456
| Type | Description |
455
457
| --- | --- |
456
-
| `dict[str, Any]` | The websocket's `scope`. |
458
+
| `Connection` | The component's websocket. |
457
459
458
-
## Use Location
459
-
460
-
This is a shortcut that returns the Websocket's `path`.
460
+
## Use Scope
461
461
462
-
You can expect this hook to provide strings such as `/idom/my_path`.
462
+
This is a shortcut that returns the Websocket's [`scope`](https://channels.readthedocs.io/en/stable/topics/consumers.html#scope).
463
463
464
464
=== "components.py"
465
465
466
466
```python
467
467
from idom import component, html
468
-
from django_idom.hooks import use_location
468
+
from django_idom.hooks import use_scope
469
469
470
470
@component
471
471
def my_component():
472
-
my_location = use_location()
473
-
return html.div(my_location)
472
+
my_scope = use_scope()
473
+
return html.div(my_scope)
474
474
```
475
475
476
476
??? example "See Interface"
@@ -483,30 +483,24 @@ You can expect this hook to provide strings such as `/idom/my_path`.
483
483
484
484
| Type | Description |
485
485
| --- | --- |
486
-
| `Location` | A object containing the current URL's `pathname` and `search` query. |
486
+
| `MutableMapping[str, Any]` | The websocket's `scope`. |
487
487
488
-
??? info "This hook's behavior will be changed in a future update"
489
-
490
-
This hook will be updated to return the browser's currently active path. This change will come in alongside IDOM URL routing support.
491
-
492
-
Check out [idom-team/idom-router#2](https://github.com/idom-team/idom-router/issues/2) for more information.
493
-
494
-
## Use Origin
488
+
## Use Location
495
489
496
-
This is a shortcut that returns the Websocket's `origin`.
490
+
This is a shortcut that returns the Websocket's `path`.
497
491
498
-
You can expect this hook to provide strings such as `http://example.com`.
492
+
You can expect this hook to provide strings such as `/idom/my_path`.
499
493
500
494
=== "components.py"
501
495
502
496
```python
503
497
from idom import component, html
504
-
from django_idom.hooks import use_origin
498
+
from django_idom.hooks import use_location
505
499
506
500
@component
507
501
def my_component():
508
-
my_origin = use_origin()
509
-
return html.div(my_origin)
502
+
my_location = use_location()
503
+
return html.div(my_location)
510
504
```
511
505
512
506
??? example "See Interface"
@@ -519,4 +513,10 @@ You can expect this hook to provide strings such as `http://example.com`.
519
513
520
514
| Type | Description |
521
515
| --- | --- |
522
-
| `str | None` | A string containing the browser's current origin, obtained from websocket headers (if available). |
516
+
| `Location` | A object containing the current URL's `pathname` and `search` query. |
517
+
518
+
??? info "This hook's behavior will be changed in a future update"
519
+
520
+
This hook will be updated to return the browser's currently active path. This change will come in alongside IDOM URL routing support.
521
+
522
+
Check out [idom-team/idom-router#2](https://github.com/idom-team/idom-router/issues/2) for more information.
0 commit comments