diff --git a/CHANGELOG.md b/CHANGELOG.md index 8506c821..1a579201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,13 @@ Using the following categories, list your changes in this order: ## [Unreleased] -Nothing (yet) +- Nothing (yet) + +## [2.0.1]- 2022-10-18 + +### Fixed + +- Ability to use `key=...` parameter on all prefabricated components ## [2.0.0]- 2022-10-17 @@ -149,7 +155,8 @@ Nothing (yet) - 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/docs/src/features/components.md b/docs/src/features/components.md index 77b086b6..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, **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,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 | `Key | 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 | `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/__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", diff --git a/src/django_idom/components.py b/src/django_idom/components.py index 3aacdfa4..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, **kwargs: Any` + Callable: A function that takes `request: HttpRequest | None, *args: Any, key: Key | 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: Key | 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: Key | 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: Key | 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): 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(), )