mattermost/mattermost

Avoid passing global state into utils/utils.tsx

Ouverte

#21 370 ouverte le 11 oct. 2022

 (3 commentaires) (0 réaction) (1 personne assignée)TypeScript (7 823 forks)batch import
Difficulty/2:MediumHacktoberfestHelp WantedTech/ReactJS

Métriques du dépôt

Stars
 (32 880 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

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: utils/utils.tsx

Proposed change in post_actions.jsx:

// 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](https://community.mattermost.com/core/channels/tickets) 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](https://community.mattermost.com/core/channels/developers).

New contributors please see our [Developer's Guide](https://developers.mattermost.com/contribute/getting-started/).

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

Guide contributeur