Skip to content

v2.0.1 #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docs/src/features/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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>

Expand Down Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion src/django_idom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 14 additions & 8 deletions src/django_idom/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""

Expand All @@ -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(
Expand All @@ -152,6 +153,7 @@ def wrapper(
request=request,
args=args,
kwargs=kwargs,
key=key,
)

return wrapper
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_app/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
)
Expand Down Expand Up @@ -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(),
)

Expand Down