BenSova
(Benjamin Sova)
1
Many APIs come with plugins that improve the power of the API and make using it more magical. However, some APIs can use a lot of plugins (like Publish) and the amount of imports you have to place on the top of your file gets huge.
@attached import would import the module it is in every time the module being imported is imported.
With that, a simple import Publish would give also import import SplashPublishPlugin too as long as SplashPublishPlugin has @attached import Publish somewhere in the module.
If that doesn't make since, think of it this way: @attached is the reverse of @_exported.
Sometimes, however, you might want to get only the primary module and none of the plugins. This would be done by placing @plain import instead of just import.
With that, if you use @plain import Publish it would only import Publish and not SplashPublishPlugin even if SplashPublishPlugin has @attached import Publish somewhere in the module.
jayton
(Jens Ayton)
2
This seems to be covering the same ground as Cross-import overlays.
2 Likes
BenSova
(Benjamin Sova)
3
They both talk about changing import functionality, but mine focuses more on adding a module to another in one on import, not changing the imported module based on what other modules are being imported.
BenSova
(Benjamin Sova)
4
Just a question for anyone looking: Should multiple @attached imports in one module lead to a build error?
BenSova
(Benjamin Sova)
5