Feature comparison with django-web-components #486
JuroOravec
started this conversation in
Ideas
Replies: 1 comment
-
Note on "Configurable component tags" - #122 is related |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As I was looking for inspiration for some features, I had a look at django-slippers and django-web-components, and compared the features provided by those libraries.
Here I'm documenting django-web-components features that are either 1) significantly diffrent from django-components, or 2) could be discussed/considered for django-components.
django-web-components
takes a slightly different approach, and does not differentiate between "props" (component input) and "attrs" (extra ad hoc kwargs passed to the template. While this is mostly OK, I don't like that this approach doesn't play nicely with building of UI kit libraries (design systems). I think that the approach we discussed in #471 is a better choice, so no action here.(added in v0.74)
<div :class="abc">
), whereas Django templating is more general and treats the underlying template as plain text.But in Python, I like the approach django-web-components took with
{% attributes %}
tag, which IMO can serve us as an inspiration.(added in v0.74)
(no action; maybe in v2?)
True
This mimicks HTML attribute behavior, where if you have e.g.
<button disabled></button>
then the value ofdisabled
is set totrue
. Vue follows this behavior too. Don't think that React does.So
{% mycomp abc=123 some_value %}
would be the same as
{% mycomp abc=123 some_value=True %}
.(no action; maybe in v2?)
{% endcomponent %}
in{% component "comp_name" %}{% endcomponent %}
. This could be possibly revisited. django-web-components creates both the "slot-ful" and "slot-less" tag variants for each component(added in v0.90)
django-web-components
component tags use the component's registered name as component tags:{% my_comp %}{% endmy_comp %}
or{% #my_comp %}
. Same was done in django-slippers, and de factor same is used also in React or Vue (e.g.<MyComponent />
).On the other hand, django-components uses a more-verbose
{% component "my_component" %}
approach.However, I really like
django-web-components
's apprach, as it allows users to configure what tags they want to use for the components. So users could decide if they want to use{% component "my_comp" %}{% endcomponent %}
or{% my_comp %}{% endmy_comp %}
or something else.(added in v0.90)
{% slot "my_slot" %}
, django-web-components interprets them as plain strings{% slot my_slot %}
. Since we already support variables, I don't see a need to change anything about it(no action)
I was nicely surprised that django-web-components has implemented this feature too.
This feature helps with organizing logic to live in those components where it is actually relevant, as opposed being lifted up to common ancestor. So IMO it is something we could consider.
(added in v0.76)
(no action)
slots
variables to dynamically access the slots passed to the component. This could be potentially useful for some advanced used cases. But unless people request it, it feels like a low priority.(added in v0.92)
Overall, I don't see added value of this as these "slot attributes" could be refactored as component inputs.
(no action)
Moreover, I think django-web-components' approach packs together 3 concepts:
1. Visual/Aesthetic - Using function instead of class, but with same functionality. Unlike us,
django-web-components
doesn't manage component's JS/CSS dependencies, so our Component class does more heavy lifting. So I think there's more value for us to use the class approach, so users can override individual methods and specify the CSS/JS dependencies. Altho I can imagine that "functional components" could be like a simplified alternative to the originalComponent
class, but it doesn't really provide any new functionality, so for me low in priority.2. Allowing to call and render a component from Python code. We could achieve something similar like
MyComponent.render_from_input(args, kwargs)
, see row "Inlined component render" in #483)3. Caching of inlined templates (discussed separately)
(no action, see #613)
CachedTemplate
, which caches inlined templates. I'm not sure if we cache this somehow, but it's again something we could take inspiration in(added in v0.97)
register
decorator@register()
,@register
,register(alert)
@register("alert")
,@register(name="alert")
,register("alert", alert)
.On the other hand, django-components supports only
@register("alert")
.However, since this is just different function signature, IMO it's nice to have, and low priority unless requested.
(no action)
django.template.Library
to which the components will be registered.. DWC allows to configure this. This could be useful for tests.(added in v0.88)
Beta Was this translation helpful? Give feedback.
All reactions