Closed JuroOravec closed 1 month ago
@EmilStenstrom @dylanjcastillo @lemontheme, since this MR got much larger than anticipated, I'd love if each of you could have a look at this and share your thoughts when you get the time, thanks!
Thanks again, really appeciate the feedback from both of you so far @EmilStenstrom @dylanjcastillo!
I rebased, and fixed/resolved the small points. I'll come back to the point on trace logging tomorrow/Thu.
I just approved it!
@JuroOravec Wanna merge and do a release? :)
Thanks both, merged!
@EmilStenstrom Here's MR for the release https://github.com/EmilStenstrom/django-components/pull/442. Not sure if I can push tags. Or can I use the github UI for that?
Update - I used the UI, looks like it also created a Release entry.
Awesome!
Just a follow up on the release - I just realized that I was making the MR from my fork. That's why it didn't work when I tried to push tags - they were pushed, but to my fork 😅
First stab at https://github.com/EmilStenstrom/django-components/issues/350.
Unlike our discussion, I made the slot resolution configurable via
"slot_context_behavior"
key, with the options below:"allow_override"
- The behavior how it was until now. Context variables defined in deeper components overshadows outer variables."prefer_root"
- The new default we've discussed in https://github.com/EmilStenstrom/django-components/issues/350. Variables defined at the "root" context ("root context" being the top-most render context) overshadow everything else, but otherwise it's the same as"allow_override"
. So if a variable is defined in the root context, then it's taken from there, and otherwise it's taken from the deepest context."isolated"
- Context variables are taken solely from the root context, and other components CANNOT override these.The reason why I went for configurable behavior is that 1) What we agreed on in https://github.com/EmilStenstrom/django-components/issues/350 was the
prefer_root
option, 2) I don't remember the exact link, but when at one point I was going through older discussions in this project, I got a feeling that there was 1-2 tickets for changing the slot behavior akin toprefer_root
/isolated
, and one forallow_override
. 3) Since I was implementing this, and the idea of supporting multiple "modes" was on the table, I'd like to have the option to have complete isolation, hence theisolated
option.I've included description and examples of each type in the settings.
I also did a bit of internal refactoring. See https://github.com/EmilStenstrom/django-components/pull/437/commits/2a8005c4d4fb16ae92679ad6997d0363e3ba37fe and https://github.com/EmilStenstrom/django-components/pull/437/commits/696e5c48d1a24a5e526e282e7b28dea015cd440e.
I also refactored the
FillNode
classes, mergingImplicitFillNode
,NamedFillNode
andBaseFillNode
. Because instead ofImplicitFillNode
, we could simply have aNamedFillNode
withis_implicit: True
(See https://github.com/EmilStenstrom/django-components/pull/437/commits/c66437792225058407a48146d7747845303f9205)TODO:
UPDATE 2024-04-16
Ooof, the refactor got out of hand 😅
ChainMap
under the"_DJANGO_COMPONENTS_FILLED_SLOTS"
key of theContext
. I had 2 issues with this:Context
object is already a stack, meaning we can pop/push layers. But alsoChainMap
was a stack. It wasn't easy for me to understand how to update theChainMap
in relation to theContext
(AKA when to pop/push what).ChainMap
, and instead all slot fills now live directly on theContext
stack. So now there is only one object that manages the stacks (Context
).ChainMap
were using theTemplate
instance as dictionary keys. My problem with this was that it was practically impossible to make sense of it using terminal. Also, my understanding is that theTemplate
instances are cached/reused by Django. Yet, in the code we modified the Nodes in theTemplate.nodelists
. So on one hand we used something that's supposed to be immutable (dict key), yet there were some parts of it that we DID change (underlying Nodes). So I wanted to simplify this, so it's clear when something IS or IS NOT immutable.ComponentNode
,SlotNode
,FillNode
)component_id
) to tie together the components, fill nodes and slots.component_id
instead of theTemplate
instance in the dicts.~What's still remaining is to update the README. Otherwise, both tests and the
sampleproject
are passing on my end.~Here's example how the logs looks like with the tracing logs and node IDs: