What's Changed
Feat
-
Instead of inlining the JS and CSS under
Component.js
andComponent.css
, you can move
them to their own files, and link the JS/CSS files withComponent.js_file
andComponent.css_file
.Even when you specify the JS/CSS with
Component.js_file
orComponent.css_file
, then you can still
access the content underComponent.js
orComponent.css
- behind the scenes, the content of the JS/CSS files
will be set toComponent.js
/Component.css
upon first access.The same applies to
Component.template_file
, which will populateComponent.template
upon first access.With this change, the role of
Component.js/css
and the JS/CSS inComponent.Media
has changed:- The JS/CSS defined in
Component.js/css
orComponent.js/css_file
is the "main" JS/CSS - The JS/CSS defined in
Component.Media.js/css
are secondary or additional
See the updated "Getting Started" tutorial
- The JS/CSS defined in
Refactor
-
The canonical way to define a template file was changed from
template_name
totemplate_file
, to align with the rest of the API.template_name
remains for backwards compatibility. When you get / settemplate_name
,
internally this is proxied totemplate_file
. -
The undocumented
Component.component_id
was removed. Instead, useComponent.id
. Changes:- While
component_id
was unique every time you instantiatedComponent
, the newid
is unique
every time you render the component (e.g. withComponent.render()
) - The new
id
is available only during render, so e.g. from withinget_context_data()
- While
-
Component's HTML / CSS / JS are now resolved and loaded lazily. That is, if you specify
template_name
/template_file
,
js_file
,css_file
, orMedia.js/css
, the file paths will be resolved only once you:- Try to access component's HTML / CSS / JS, or
- Render the component.
Read more on Accessing component's HTML / JS / CSS.
-
Component inheritance:
- When you subclass a component, the JS and CSS defined on parent's
Media
class is now inherited by the child component. - You can disable or customize Media inheritance by setting
extend
attribute on theComponent.Media
nested class. This work similarly to Django'sMedia.extend
. - When child component defines either
template
ortemplate_file
, both of parent'stemplate
andtemplate_file
are ignored. The same applies tojs_file
andcss_file
.
- When you subclass a component, the JS and CSS defined on parent's
-
Autodiscovery now ignores files and directories that start with an underscore (
_
), except__init__.py
-
The Signals emitted by or during the use of django-components are now documented, together the
template_rendered
signal.
Full Changelog: 0.123...0.124