-
Notifications
You must be signed in to change notification settings - Fork 17
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
Rule: no-mutation-in-pure-functions
#6
Comments
I'm not sure i understand - how it is supposed to work? For e.g., i think, this kind of mutation would be entierly correct: (state, payload) => {
const copyState = deepCopy(state);
const copyPayload = deepCopy(payload);
copyPayload.foo = "bar";
copyState.some = copyPayload;
return copyState;
}
Another problem is that there is no way to proof that this Looks like, it is only options that are secured from false warnings, are:
|
Also there is another case that is affects "purity" of functions - reading from outer state that can be changed during app lifetime. const box = { ... };
const RED = 'red';
$store.on(event, (state, payload) => {
// all of this this is reading from outer state which is side-effect
// and may lead to observable changes in function behaviour
const date = new Date()
const otherState = $another.getState()
// `box` is not readonly or frozen object, we cannot prove that is not mutable
// should be warned, i guess
const someData = box[payload];
// RED is a immutable primitive constant, will never change
// this should not be warned, i guess
const nextState = {...state, color: RED}
}) |
no-mutation-in-pure-functions
Some functions in effector API should be pure:
.on
-callfn
) insample
guard
,.filter
and.filterMap
.map
and.prepend
We cannot prove the purity functions by ESLint rule, but we can forbid mutations in these cases.
The text was updated successfully, but these errors were encountered: