Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Concatenated Array fields on set #179

Open
EdenCoder opened this issue May 25, 2017 · 5 comments
Open

Concatenated Array fields on set #179

EdenCoder opened this issue May 25, 2017 · 5 comments
Labels

Comments

@EdenCoder
Copy link
Contributor

		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
Copy link
Owner

Oh yes, you are right!

@Mywifi
Copy link

Mywifi commented Jan 17, 2018

i meet the same problem, can you fix this?

@vadimdemedes
Copy link
Owner

vadimdemedes commented Jan 20, 2018

@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
Copy link

How trivial would this be? is a lodash.set enough?

@LennyPenny
Copy link

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);
    };
};

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

No branches or pull requests

4 participants