From bbc2fd8a3b00411a5df2a6bc73359606fa7a47fe Mon Sep 17 00:00:00 2001
From: Archmonger <16909269+Archmonger@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:50:12 -0700
Subject: [PATCH 1/4] v2.0.1
---
CHANGELOG.md | 6 +++++-
docs/src/features/components.md | 4 +++-
src/django_idom/components.py | 20 +++++++++++++-------
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8506c821..7f761e7b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,11 @@ Using the following categories, list your changes in this order:
## [Unreleased]
-Nothing (yet)
+## [2.0.1]- 2022-10-17
+
+### Fixed
+
+- Ability to use `key=...` parameter on all prefabricated components
## [2.0.0]- 2022-10-17
diff --git a/docs/src/features/components.md b/docs/src/features/components.md
index 77b086b6..06db7624 100644
--- a/docs/src/features/components.md
+++ b/docs/src/features/components.md
@@ -39,7 +39,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
| Type | Description |
| --- | --- |
- | `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, **kwargs: Any` and returns an IDOM component. |
+ | `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, key: Any | None, **kwargs: Any` and returns an IDOM component. |
??? warning "Existing limitations"
@@ -261,6 +261,7 @@ Allows you to defer loading a CSS stylesheet until a component begins rendering.
| Name | Type | Description | Default |
| --- | --- | --- | --- |
| static_path | `str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
+ | key | `Any | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
**Returns**
@@ -338,6 +339,7 @@ Allows you to defer loading JavaScript until a component begins rendering. This
| Name | Type | Description | Default |
| --- | --- | --- | --- |
| static_path | `str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
+ | key | `Any | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
**Returns**
diff --git a/src/django_idom/components.py b/src/django_idom/components.py
index 3aacdfa4..ee88098c 100644
--- a/src/django_idom/components.py
+++ b/src/django_idom/components.py
@@ -131,7 +131,7 @@ def view_to_component(
perfectly adhere to HTML5.
Returns:
- Callable: A function that takes `request: HttpRequest | None, *args: Any, **kwargs: Any`
+ Callable: A function that takes `request: HttpRequest | None, *args: Any, key: Any | None, **kwargs: Any`
and returns an IDOM component.
"""
@@ -142,6 +142,7 @@ def decorator(view: Callable | View):
def wrapper(
request: HttpRequest | None = None,
*args: Any,
+ key: Any | None = None,
**kwargs: Any,
):
return _view_to_component(
@@ -152,6 +153,7 @@ def wrapper(
request=request,
args=args,
kwargs=kwargs,
+ key=key,
)
return wrapper
@@ -164,15 +166,17 @@ def _django_css(static_path: str):
return html.style(_cached_static_contents(static_path))
-def django_css(static_path: str):
+def django_css(static_path: str, key: Any | None = None):
"""Fetches a CSS static file for use within IDOM. This allows for deferred CSS loading.
Args:
static_path: The path to the static file. This path is identical to what you would
- use on a `static` template tag.
+ use on a `static` template tag.
+ key: A key to uniquely identify this component which is unique amongst a component's
+ immediate siblings
"""
- return _django_css(static_path=static_path)
+ return _django_css(static_path=static_path, key=key)
@component
@@ -180,15 +184,17 @@ def _django_js(static_path: str):
return html.script(_cached_static_contents(static_path))
-def django_js(static_path: str):
+def django_js(static_path: str, key: Any | None = None):
"""Fetches a JS static file for use within IDOM. This allows for deferred JS loading.
Args:
static_path: The path to the static file. This path is identical to what you would
- use on a `static` template tag.
+ use on a `static` template tag.
+ key: A key to uniquely identify this component which is unique amongst a component's
+ immediate siblings
"""
- return _django_js(static_path=static_path)
+ return _django_js(static_path=static_path, key=key)
def _cached_static_contents(static_path: str):
From 0c4e23a8b9adbf18329c0750ead3b002550e2a8e Mon Sep 17 00:00:00 2001
From: Archmonger <16909269+Archmonger@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:52:04 -0700
Subject: [PATCH 2/4] add tests
---
tests/test_app/components.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/test_app/components.py b/tests/test_app/components.py
index b4140b6f..f0a405f0 100644
--- a/tests/test_app/components.py
+++ b/tests/test_app/components.py
@@ -101,7 +101,7 @@ def use_origin():
def django_css():
return html.div(
{"id": "django-css"},
- django_idom.components.django_css("django-css-test.css"),
+ django_idom.components.django_css("django-css-test.css", key="test"),
html.div({"style": {"display": "inline"}}, "django_css: "),
html.button("This text should be blue."),
html.hr(),
@@ -115,7 +115,7 @@ def django_js():
html.div(
{"id": "django-js", "data-success": success},
f"django_js: {success}",
- django_idom.components.django_js("django-js-test.js"),
+ django_idom.components.django_js("django-js-test.js", key="test"),
),
html.hr(),
)
@@ -280,7 +280,7 @@ def _render_items(items, toggle_item):
def view_to_component_sync_func_compatibility():
return html.div(
{"id": inspect.currentframe().f_code.co_name},
- _view_to_component_sync_func_compatibility(),
+ _view_to_component_sync_func_compatibility(key="test"),
html.hr(),
)
From 3277c96899a12190b92c63dddff1f8938b0e26f8 Mon Sep 17 00:00:00 2001
From: Archmonger <16909269+Archmonger@users.noreply.github.com>
Date: Tue, 18 Oct 2022 00:34:59 -0700
Subject: [PATCH 3/4] bump pkg version
---
CHANGELOG.md | 7 +++++--
src/django_idom/__init__.py | 2 +-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f761e7b..1a579201 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,9 @@ Using the following categories, list your changes in this order:
## [Unreleased]
-## [2.0.1]- 2022-10-17
+- Nothing (yet)
+
+## [2.0.1]- 2022-10-18
### Fixed
@@ -153,7 +155,8 @@ Using the following categories, list your changes in this order:
- Support for IDOM within the Django
-[unreleased]: https://github.com/idom-team/django-idom/compare/2.0.0...HEAD
+[unreleased]: https://github.com/idom-team/django-idom/compare/2.0.1...HEAD
+[2.0.1]: https://github.com/idom-team/django-idom/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/idom-team/django-idom/compare/1.2.0...2.0.0
[1.2.0]: https://github.com/idom-team/django-idom/compare/1.1.0...1.2.0
[1.1.0]: https://github.com/idom-team/django-idom/compare/1.0.0...1.1.0
diff --git a/src/django_idom/__init__.py b/src/django_idom/__init__.py
index 39893c7e..04bb0519 100644
--- a/src/django_idom/__init__.py
+++ b/src/django_idom/__init__.py
@@ -3,7 +3,7 @@
from django_idom.websocket.paths import IDOM_WEBSOCKET_PATH
-__version__ = "2.0.0"
+__version__ = "2.0.1"
__all__ = [
"IDOM_WEBSOCKET_PATH",
"IdomWebsocket",
From 5f9f468aaed3e30a1d5eb45e6ebfae95b132b3db Mon Sep 17 00:00:00 2001
From: Archmonger <16909269+Archmonger@users.noreply.github.com>
Date: Tue, 18 Oct 2022 12:41:07 -0700
Subject: [PATCH 4/4] change key type hint
---
docs/src/features/components.md | 6 +++---
src/django_idom/components.py | 10 +++++-----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/docs/src/features/components.md b/docs/src/features/components.md
index 06db7624..c8a110f9 100644
--- a/docs/src/features/components.md
+++ b/docs/src/features/components.md
@@ -39,7 +39,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
| Type | Description |
| --- | --- |
- | `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, key: Any | None, **kwargs: Any` and returns an IDOM component. |
+ | `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, key: Key | None, **kwargs: Any` and returns an IDOM component. |
??? warning "Existing limitations"
@@ -261,7 +261,7 @@ Allows you to defer loading a CSS stylesheet until a component begins rendering.
| Name | Type | Description | Default |
| --- | --- | --- | --- |
| static_path | `str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
- | key | `Any | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
+ | key | `Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
**Returns**
@@ -339,7 +339,7 @@ Allows you to defer loading JavaScript until a component begins rendering. This
| Name | Type | Description | Default |
| --- | --- | --- | --- |
| static_path | `str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
- | key | `Any | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
+ | key | `Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
**Returns**
diff --git a/src/django_idom/components.py b/src/django_idom/components.py
index ee88098c..8c9ff3fa 100644
--- a/src/django_idom/components.py
+++ b/src/django_idom/components.py
@@ -11,7 +11,7 @@
from django.urls import reverse
from django.views import View
from idom import component, hooks, html, utils
-from idom.types import ComponentType, VdomDict
+from idom.types import ComponentType, Key, VdomDict
from django_idom.config import IDOM_CACHE, IDOM_VIEW_COMPONENT_IFRAMES
from django_idom.types import ViewComponentIframe
@@ -131,7 +131,7 @@ def view_to_component(
perfectly adhere to HTML5.
Returns:
- Callable: A function that takes `request: HttpRequest | None, *args: Any, key: Any | None, **kwargs: Any`
+ Callable: A function that takes `request: HttpRequest | None, *args: Any, key: Key | None, **kwargs: Any`
and returns an IDOM component.
"""
@@ -142,7 +142,7 @@ def decorator(view: Callable | View):
def wrapper(
request: HttpRequest | None = None,
*args: Any,
- key: Any | None = None,
+ key: Key | None = None,
**kwargs: Any,
):
return _view_to_component(
@@ -166,7 +166,7 @@ def _django_css(static_path: str):
return html.style(_cached_static_contents(static_path))
-def django_css(static_path: str, key: Any | None = None):
+def django_css(static_path: str, key: Key | None = None):
"""Fetches a CSS static file for use within IDOM. This allows for deferred CSS loading.
Args:
@@ -184,7 +184,7 @@ def _django_js(static_path: str):
return html.script(_cached_static_contents(static_path))
-def django_js(static_path: str, key: Any | None = None):
+def django_js(static_path: str, key: Key | None = None):
"""Fetches a JS static file for use within IDOM. This allows for deferred JS loading.
Args: