Concatenated Array fields on set
Opened this issue · 5 comments
EdenCoder commented
case ActionTypes.SET:
return merge(state, action.fields);
When using set
on a field of type Array
, the field is concatenated. It should be overwritten shouldn't it?
vadimdemedes commented
Oh yes, you are right!
Mywifi commented
i meet the same problem, can you fix this?
vadimdemedes commented
@Mywifi I don't have enough time for this, but I'd happily help you resolve this. Would you be interested in making a PR for it?
LennyPenny commented
How trivial would this be? is a lodash.set enough?
LennyPenny commented
I fixed this temporarily with a middleware as I'm not knowledgable enough with lodash and reactive stuff to fix the underlying issue
Here it is if you need it @EdenCoder
import { ActionTypes } from "mongorito";
export default () => {
return ({ model }) => next => action => {
if (action.type === ActionTypes.SET) {
for (const key in action.fields) {
if (Array.isArray(action.fields[key])) {
model.unset(key);
}
}
}
return next(action);
};
};