Currently, using a loop in a Redcr reducer can end up mutably editing the state. For example
interface StringState {
str: String
}
const reducer = redcr((state: StringState) => {
for (let i = 0; i < 3; i++) {
state.str += 'A';
}
});
Will produce
const reducer = (state) => {
for (let i = 0; i < 3; i++) {
state.str += 'A';
}
return state;
};
It should probably work similar to how if-statements are handled, and continuously reassign the state
const reducer = (state) => {
for (let i = 0; i < 3; i++) {
state = {
...state,
str: state.str + 'A'
}
}
return state;
};
Could explore loop unrolling too if the number of iterations is a compile-time constant.
How often is a loop actually useful in a reducer though?
Currently, using a loop in a Redcr reducer can end up mutably editing the state. For example
Will produce
It should probably work similar to how if-statements are handled, and continuously reassign the state
Could explore loop unrolling too if the number of iterations is a compile-time constant.
How often is a loop actually useful in a reducer though?