Fluture
Fluture copied to clipboard
Add "pure"-annotations to the source to aid code minification
Tools like Rollup and UglifyJS can make better optimizations if they know certain pieces of code will never have side-effects. One way to let these tools know is via /*#__PURE__*/
-annotations.
There's a chance that even after marking things as pure, tree shaking still won't be very beneficial, due to the way debugMode
is implemented. When calling debugMode(true)
, a function deep down in the Fluture code is replaced. This function is used by the entire Fluture codebase. And as the possibility for it to be replaced should be considered a mutation, I fear that by extension the entire codebase should be considered mutable. I'll have to do some experiments to verify whether this is the case, and if I can work around it.
We would love to use Fluture at Unsplash but unfortunately we're blocked by this. Is there anything we can do to help you move this forward?
I think the most straight-forward approach is to reimplement debug mode using an environment variable, checking process.env.FLUTURE_DEBUG
or perhaps self.FLUTURE_DEBUG
in browsers, making it so once the module resolves, the debug mode is determined, and can't be changed later.
This will have the added benefit that multiple compatible versions of Fluture that have been installed side by side will all use the same source to enable or disable their debug modes, giving users who enable debug mode a more uniform experience.