bedrock icon indicating copy to clipboard operation
bedrock copied to clipboard

Make mixins defined in styleguide accessible globally

Open Wolfr opened this issue 4 years ago • 2 comments

Idea for Bedrock.

If you define a mixin anywhere in content/_components/<your-component> it could become available in all templates.

This could be done by Bedrock scanning the contents of all files in _components and taking out any mixins, and then adding all those mixins to the global “namespace”.

The manual way to do right now is define mixins in content/_mixins/all manually. The problem with this is that it makes your code live both in _components and in _mixins.

It would be cleaner if there is a single place for your definition.

Wolfr avatar Aug 10 '21 14:08 Wolfr

Reading this idea a few months later it sounds a bit fragile, but co-location of code would still be nice, and would alllow you to work in Bedrock in a way that's more like in most modern JS frameworks.

Wolfr avatar Nov 16 '21 10:11 Wolfr

Reading this again it sounds like it could make Bedrock slower if we are not careful.

One other implementation strategy might be to put the mixin in a specific format so that it becomes scannable. E.g. all mixins are in a filled called *.mixin.pug

And thus we can join the contents of all of these files and then make those mixins available in the global namespace.

However I don't think we can implement this without requiring a server restart.

Wolfr avatar Nov 29 '21 09:11 Wolfr