Fluture icon indicating copy to clipboard operation
Fluture copied to clipboard

Add "pure"-annotations to the source to aid code minification

Open Avaq opened this issue 5 years ago • 3 comments

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.

Avaq avatar May 31 '19 11:05 Avaq

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.

Avaq avatar Oct 29 '19 11:10 Avaq

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?

OliverJAsh avatar Jan 15 '22 08:01 OliverJAsh

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.

Avaq avatar Jan 16 '22 13:01 Avaq