Mattermost-server: Avoid passing global state into actions in Webapp

Created on 2 Apr 2020  路  3Comments  路  Source: mattermost/mattermost-server

This ticket is regarding the way we handle state actions in webapp. Similar to the util functions, we are passing the state and dispatch directly from our imported global store in the action creators.

In order to make the action creators more predictable and improve their testability we need to refactor the way we handle action creators and make sure they are always passed to mapDispatchToProps in the connected components.

Files:
global_actions.jsx
user_actions.jsx
websocket_actions.jsx
logged_in.jsx
browser_store.jsx

Proposed change in post_actions.jsx:


const addPostToSearchResults = (postId) => (dispatch, getState) => {
// get the state from getState
  ......
  dispatch({
            type: SearchTypes.RECEIVED*SEARCH*POSTS,
            data: {posts, order: newResults},
        });
} 

and then we call it dispatch(addPostToSearchResults(postId));


If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.

New contributors please see our Developer's Guide.

JIRA: https://mattermost.atlassian.net/browse/MM-22995

AreTechnical Debt Hard Help Wanted TecReactJS

All 3 comments

can I take it?

Can I work on this ?

Hey @diode thank you for picking this issue! If you need any help I am available on the community chat - @nevyana.angelova

Was this page helpful?
0 / 5 - 0 ratings