Skip to content

Use redux-actions instead of combineReducers#2

Open
Andrii-D wants to merge 3 commits intomasterfrom
redux-actions
Open

Use redux-actions instead of combineReducers#2
Andrii-D wants to merge 3 commits intomasterfrom
redux-actions

Conversation

@Andrii-D
Copy link
Owner

@Andrii-D Andrii-D commented Oct 9, 2018

No description provided.

@Andrii-D Andrii-D requested a review from oleg-preply October 10, 2018 08:20
Copy link
Collaborator

@oleg-preply oleg-preply left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great progress!!! 😄

setLanguages: languages => dispatch (setLanguages (languages)),
setScreens: screens => dispatch (setScreens (screens)),
resetState: () => dispatch(resetState()),
abstractSetter: (data) => dispatch(abstractSetter(data)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be just const mapDispatchToProps = { resetState, abstractSetter }


const App = connect (mapStateToProps, mapDispatchToProps) (ConnectedApp);
const App = connect(mapStateToProps, mapDispatchToProps) (ConnectedApp);
export default App;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export default connect(mapStateToProps, mapDispatchToProps) (ConnectedApp); saves you one line :trollface:


export const resetState = createAction('RESET_STATE'); // TODO: doesn't work correctly (languages and screens multiselect is not re-rendered)

export const abstractSetter = createAction('SET');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstractions in Redux are dangerous things since might become unmaintainable at some point.

Would suggest firstly split it back to separate actions/reducers and after that use combineActions (or other way of doing that) of redux-actions

const reducer = handleActions(
{
[resetState]: () => ({ ...initialState}),
[abstractSetter]: (state, {payload: {value, type}}) => { let newState = {...state}; newState[type] = value; return newState; },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be shorter:
[abstractSetter]: (state, {payload: {value, type}}) => ({...state, [type]: value }),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments