Calling functions for their side-effects
See original GitHub issueIt is fairly common to have functions that register information at the global level. Doing this involves some syntax that usually quite ugly. The two ways of doing this are to set a variable that is then disregarded or to assign a property to the output of the function which returns null thus causing the property to not be output.
Calling functions strictly for their side-effects is not something I’m particularly keen on encouraging – especially since Sass functions mostly return a useful value. That said, I think we should have the conversation about whether we should allow a bare function to be called at the root-level of the stylesheet since I’ve had several people ask me for this feature.
Example:
@import "some-framework";
register-framework-thing(a-thing, 10px);
Note: we could add a directive to do this with existing syntax rules. but this offers so little over @include
that I don’t think it’s worth it.
@nex3 thoughts?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:30 (9 by maintainers)
Top GitHub Comments
Well, I’d rather drop mixins altogether. And instead have a function, which could return CSS fragments and thus act as mixins.
So, instead of this:
There will be only this way:
This will eliminate the current issue with side-effects since the function will become the only and clear way to reuse code chunks and declare side effects.
And since distinguishing between mixins and functions will be no longer there, it will make a lot of things much clearer. For instance, it will be possible to use functions, which return CSS fragments, within other functions to achieve some complex effect. This is something that’s not that easy when you need to pass a piece of code from function to mixin or the other way.
Some might not like
@return
of CSS fragment part, but I found that way much clearer since it nicely decouples logic (part with$final-border
) from actual output.I tend to agree with @chriseppstein
Currently we already have very blurred mixins and functions, and out-of-place usage of mixins to make side effects. Mixins originally had to produce styles, not any side-effects, so it always felt to me rather like a hack. Thus I’m voting for a clear way to use functions for same purpose.
I wonder why @nex3 leaved this discussion? Is this like an act of protest? 😃