Skip to content

Commit 09d11f0

Browse files
authored
v2.0.1 (#107)
- Ability to use `key=...` parameter on all prefabricated components
1 parent 95095ea commit 09d11f0

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

CHANGELOG.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ Using the following categories, list your changes in this order:
2222

2323
## [Unreleased]
2424

25-
Nothing (yet)
25+
- Nothing (yet)
26+
27+
## [2.0.1]- 2022-10-18
28+
29+
### Fixed
30+
31+
- Ability to use `key=...` parameter on all prefabricated components
2632

2733
## [2.0.0]- 2022-10-17
2834

@@ -149,7 +155,8 @@ Nothing (yet)
149155

150156
- Support for IDOM within the Django
151157

152-
[unreleased]: https://github.com/idom-team/django-idom/compare/2.0.0...HEAD
158+
[unreleased]: https://github.com/idom-team/django-idom/compare/2.0.1...HEAD
159+
[2.0.1]: https://github.com/idom-team/django-idom/compare/2.0.0...2.0.1
153160
[2.0.0]: https://github.com/idom-team/django-idom/compare/1.2.0...2.0.0
154161
[1.2.0]: https://github.com/idom-team/django-idom/compare/1.1.0...1.2.0
155162
[1.1.0]: https://github.com/idom-team/django-idom/compare/1.0.0...1.1.0

docs/src/features/components.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
3939

4040
| Type | Description |
4141
| --- | --- |
42-
| `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, **kwargs: Any` and returns an IDOM component. |
42+
| `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, key: Key | None, **kwargs: Any` and returns an IDOM component. |
4343

4444
??? warning "Existing limitations"
4545

@@ -261,6 +261,7 @@ Allows you to defer loading a CSS stylesheet until a component begins rendering.
261261
| Name | Type | Description | Default |
262262
| --- | --- | --- | --- |
263263
| 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 |
264+
| key | `Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
264265

265266
<font size="4">**Returns**</font>
266267

@@ -338,6 +339,7 @@ Allows you to defer loading JavaScript until a component begins rendering. This
338339
| Name | Type | Description | Default |
339340
| --- | --- | --- | --- |
340341
| 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 |
342+
| key | `Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `None` |
341343

342344
<font size="4">**Returns**</font>
343345

src/django_idom/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django_idom.websocket.paths import IDOM_WEBSOCKET_PATH
44

55

6-
__version__ = "2.0.0"
6+
__version__ = "2.0.1"
77
__all__ = [
88
"IDOM_WEBSOCKET_PATH",
99
"IdomWebsocket",

src/django_idom/components.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.urls import reverse
1212
from django.views import View
1313
from idom import component, hooks, html, utils
14-
from idom.types import ComponentType, VdomDict
14+
from idom.types import ComponentType, Key, VdomDict
1515

1616
from django_idom.config import IDOM_CACHE, IDOM_VIEW_COMPONENT_IFRAMES
1717
from django_idom.types import ViewComponentIframe
@@ -131,7 +131,7 @@ def view_to_component(
131131
perfectly adhere to HTML5.
132132
133133
Returns:
134-
Callable: A function that takes `request: HttpRequest | None, *args: Any, **kwargs: Any`
134+
Callable: A function that takes `request: HttpRequest | None, *args: Any, key: Key | None, **kwargs: Any`
135135
and returns an IDOM component.
136136
"""
137137

@@ -142,6 +142,7 @@ def decorator(view: Callable | View):
142142
def wrapper(
143143
request: HttpRequest | None = None,
144144
*args: Any,
145+
key: Key | None = None,
145146
**kwargs: Any,
146147
):
147148
return _view_to_component(
@@ -152,6 +153,7 @@ def wrapper(
152153
request=request,
153154
args=args,
154155
kwargs=kwargs,
156+
key=key,
155157
)
156158

157159
return wrapper
@@ -164,31 +166,35 @@ def _django_css(static_path: str):
164166
return html.style(_cached_static_contents(static_path))
165167

166168

167-
def django_css(static_path: str):
169+
def django_css(static_path: str, key: Key | None = None):
168170
"""Fetches a CSS static file for use within IDOM. This allows for deferred CSS loading.
169171
170172
Args:
171173
static_path: The path to the static file. This path is identical to what you would
172-
use on a `static` template tag.
174+
use on a `static` template tag.
175+
key: A key to uniquely identify this component which is unique amongst a component's
176+
immediate siblings
173177
"""
174178

175-
return _django_css(static_path=static_path)
179+
return _django_css(static_path=static_path, key=key)
176180

177181

178182
@component
179183
def _django_js(static_path: str):
180184
return html.script(_cached_static_contents(static_path))
181185

182186

183-
def django_js(static_path: str):
187+
def django_js(static_path: str, key: Key | None = None):
184188
"""Fetches a JS static file for use within IDOM. This allows for deferred JS loading.
185189
186190
Args:
187191
static_path: The path to the static file. This path is identical to what you would
188-
use on a `static` template tag.
192+
use on a `static` template tag.
193+
key: A key to uniquely identify this component which is unique amongst a component's
194+
immediate siblings
189195
"""
190196

191-
return _django_js(static_path=static_path)
197+
return _django_js(static_path=static_path, key=key)
192198

193199

194200
def _cached_static_contents(static_path: str):

tests/test_app/components.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def use_origin():
101101
def django_css():
102102
return html.div(
103103
{"id": "django-css"},
104-
django_idom.components.django_css("django-css-test.css"),
104+
django_idom.components.django_css("django-css-test.css", key="test"),
105105
html.div({"style": {"display": "inline"}}, "django_css: "),
106106
html.button("This text should be blue."),
107107
html.hr(),
@@ -115,7 +115,7 @@ def django_js():
115115
html.div(
116116
{"id": "django-js", "data-success": success},
117117
f"django_js: {success}",
118-
django_idom.components.django_js("django-js-test.js"),
118+
django_idom.components.django_js("django-js-test.js", key="test"),
119119
),
120120
html.hr(),
121121
)
@@ -280,7 +280,7 @@ def _render_items(items, toggle_item):
280280
def view_to_component_sync_func_compatibility():
281281
return html.div(
282282
{"id": inspect.currentframe().f_code.co_name},
283-
_view_to_component_sync_func_compatibility(),
283+
_view_to_component_sync_func_compatibility(key="test"),
284284
html.hr(),
285285
)
286286

0 commit comments

Comments
 (0)