Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomizer getConfig mutates provided object, should be pure #391

Closed
adamdharrington opened this issue Jul 8, 2021 · 0 comments · Fixed by #392
Closed

Atomizer getConfig mutates provided object, should be pure #391

adamdharrington opened this issue Jul 8, 2021 · 0 comments · Fixed by #392

Comments

@adamdharrington
Copy link

Problem

We are using Atomizer in a Webpack plugin with multiple entry points feeding in a common config object for breakpoints and custom definitions. The common config object passed as second argument to Atomizer.getConfig() is injected with a classes property which seems to grow with additional classes each time it is called leading to later calls including all classes from previous calls.

My workaround will be to explicitly create a new object for each call however I don't believe the input object should be mutated in this case.

Expectation

getConfig should be a pure function (based on it's name and implied usage)

Reproduction

Call getConfig twice with different sources but the same config definition (second argument) and see the second will include all references from the first file processed.

Fix

Return a new object and add a unit test to ensure the arguments are the same before and after the function is called.

atomizer/src/atomizer.js

Lines 125 to 130 in 0f0fbf4

Atomizer.prototype.getConfig = function (classNames/*:string[]*/, config/*:AtomizerConfig*/)/*:AtomizerConfig*/ {
config = config || { classNames: [] };
// merge classnames with config
config.classNames = this.sortCSS(_.union(classNames || [], config.classNames));
return config;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant