I,m working on one project and I want to update my data in the below object I use Lodash's _.set method so in the future this below object can be anything but sub-object like Buttons and Content are the same because this thing is needed in website and they are diff for diff template.
"content_navData": {
"path": ["content", "content_navData"],
"logo": {
"path": ["content", "content_navData", "logo"],
"imgUrl": "https://source.unsplash.com/user/erondu/50x50",
"settings": {
"class": ["defaultLogo"]
}
},
"navLinks": {
"path": ["content", "content_navData", "navLinks"],
"Home": {
"path": ["content", "content_navData", "navLinks", "Home"],
"title": "Home",
"type": "link",
"href": "/",
"setting": {
"class": ["defaultLink"],
"isActive": true
}
},
"About": {
"path": ["content", "content_navData", "navLinks", "About"],
"title": "About",
"type": "link",
"href": "/about",
"setting": {
"class": ["defaultLink"],
"isActive": true
}
},
"Blog": {
"path": ["content", "content_navData", "navLinks", "Blog"],
"title": "Blog",
"type": "link",
"href": "/blog",
"setting": {
"class": ["defaultLink"],
"isActive": true
}
}
},
"navButtons": {
"LogIn": {
"title": "Log in",
"type": "button",
"setting": {
"class": ["defaultButton", "ghostButton"],
"isActive": true
}
},
"SignUp": {
"title": "Sign Up",
"type": "button",
"setting": {
"class": ["defaultButton", "ghostButton"],
"isActive": true
}
}
}
},
I'm using react and redux for state and data management so I don't want to define the same reducer for diff Template object.
As you can see here I don't want a hardcoded path for reducer so I diced that i us path
key in each object that has a proper path for that obj. I this the right way to a big project??
const componentReducer = (state = initialState, action) => {
switch (action.type) {
case componentEditType.EDIT_DESCRIPTION:
return _.set(initialState, ['content', 'hero', 'data', 'description'], action.payload)
}
}