Skip to content

Commit

Permalink
v2.0.1 (#107)
Browse files Browse the repository at this point in the history
-   Ability to use `key=...` parameter on all prefabricated components
  • Loading branch information
Archmonger authored Oct 18, 2022
1 parent 95095ea commit 09d11f0
Showing 5 changed files with 30 additions and 15 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion docs/src/features/components.md
Original file line number Diff line number Diff line change
@@ -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` |

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

@@ -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` |

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

2 changes: 1 addition & 1 deletion src/django_idom/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
22 changes: 14 additions & 8 deletions src/django_idom/components.py
Original file line number Diff line number Diff line change
@@ -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,31 +166,35 @@ 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
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):
6 changes: 3 additions & 3 deletions tests/test_app/components.py
Original file line number Diff line number Diff line change
@@ -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(),
)

0 comments on commit 09d11f0

Please sign in to comment.