mattermost / mattermost

Mattermost is an open source platform for secure collaboration across the entire software development lifecycle..
https://mattermost.com
Other
30.68k stars 7.36k forks source link

Avoid passing global state into websocket_actions.jsx in webapp #21249

Open mattermod opened 2 years ago

mattermod commented 2 years ago

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: websocket_actions.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));

NOTE: Calling getState is fine as long as it's coming from thunk inside the component. We don't want to import it from stores/redux_store


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-47360

AbhinavVihan commented 2 years ago

I'd like to work on this please.

hmhealey commented 2 years ago

Let us know if you run into any issues with this. It might be a bit harder to remove the global state from this file in particular since the websocket code runs outside of the usual Redux flow, but hopefully, we can remove most of it at least.