Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

javascript - Implement many-to-many relationship in Redux

I want to implement many-to-many relationship in Redux. My reducer looks like this:

const INITIAL_ARTICLES = {
    articles: [],
    tags: []
}
const articles = (state = INITIAL_ARTICLES, action) => {
    switch(action.type){
        case 'ADD_ARTICLE':
            return {
                ...state,
                articles: [...state.articles, action.item]
            }
        default:
            return state
    }
}

I created many-to-many relationshiop in Laravel. All articles is fetch from my db but I want to implement many-to-many relationship. The best for me would be if this state would look like this:

const INITIAL_ARTICLES = {
    articles: [
        {
            id: 1,
            title: "My firs article",
            tags: [
                {
                    id: 1,
                    name: "tag"
                },
                {
                    id: 2,
                    name: "cats"
                }
            ]
        }
    ]
}

Is it possible? How can I implement this relatioship with those or other way? I think primarilly about reducer.

question from:https://stackoverflow.com/questions/65857099/implement-many-to-many-relationship-in-redux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...