Replies: 1 comment 1 reply
-
Hey, glad you're enjoying them. You're welcome! Yeah a few scoping patterns are described in the 💎 Conventions & Tips in the readme. As mentioned,
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Thanks for this interesting little library and for
css-scope-inline
, too!I've been using both in a new project, and have run into a touch of friction that perhaps someone watching the discussions will have some thoughts on.
I'm using boring old Django templates to render HTML.
When I want a little nugget of JavaScript somewhere, I generally find that I want to ensure the document is ready, so I tend to do:
My templates tend to have lots of
{% include %}
s and look sort of component-y, each containing a few lines of css and js; this seems to mesh well withsurreal
andcss-scope-inline
.As a result, my final rendered page often has many small
<script>
tags. Since bare<script>
tags don't introduce new block scopes, I discover at runtime thatself
is already defined, and my code fails to run.As a result, I've resorted to using IIFEs everywhere:
This isn't a big deal, but it does feel a little less elegant.
Alternatively, I suppose I could make all my scripts
type="module"
since this does introduce new block scope... but this doesn't seem to work in practice. (Not sure if that's asurreal
issue or something more basic.)How do folks tend to structure their code here?
Beta Was this translation helpful? Give feedback.
All reactions