Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Redux Toolkit and ducks pattern #2812

Draft
wants to merge 26 commits into
base: dev
Choose a base branch
from
Draft

Conversation

julienben
Copy link
Member

@julienben julienben commented Nov 21, 2019

React Boilerplate

This is a draft PR which aggregates all the changes as we work towards switching to Redux Toolkit and the ducks pattern.

Related issue:

Changes so far

  • Added Redux Toolkit (RTK)
  • Removed the explicit dependency on Redux, since RTK re-exports everything.
  • Converted the store setup logic in configureStore.js to use RTK's configureStore method
  • Updated the sample and template apps:
    • Created an RTK "slice" for all the HomePage and LocaleToggle features
    • Moved App container's reducer/saga/actions into a new container called ReposManager
    • Deleted all redundant actions/constants/reducer files
    • Determined ownership of repos in saga so that RepoListItem can become a component
    • Updated all broken tests and write new tests for slices
  • Added ESLint exception for "slice" files so that we can remove ESLint exceptions
  • Removed obsolete store setup tests that checked for calling the DevTools Extension global API

To Do

@coveralls
Copy link

coveralls commented Nov 21, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling c252e9d on redux-toolkit-switch into cb0da03 on dev.

* Update generators for switch to Redux Toolkit

* Remove useless comments from tests

* Turn multiline comment into many single line comments ;)
@julienben julienben mentioned this pull request Nov 21, 2019
6 tasks
# Conflicts:
#	app/containers/App/index.js
#	app/containers/LanguageProvider/reducer.js
#	app/containers/LocaleToggle/index.js
#	internals/templates/containers/LanguageProvider/reducer.js
#	package.json
# Conflicts:
#	app/containers/App/selectors.js
#	package.json
@Can-Sahin
Copy link
Member

Here I don't understand why there is a ReposManager. I am pretty familiar with RTK now and with ducks pattern too. Only Homepage is using ReposManager so it can be easily its own slice. No other component is using it. I am super against to using managers. I am backend developer and it's a really bad pattern to start calling things managers and putting them into separate folders. People walked away from it years ago

},
reposLoaded(state, action) {
const { repos } = action.payload;
state.repositories = repos;

Choose a reason for hiding this comment

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

Mutating state directly is an antipattern. You should return { ...state, repos }

Copy link

Choose a reason for hiding this comment

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

RTK uses immer inside. So you can use it this way

@Tommoore96
Copy link

@all-contributors please add Tommoore96 for code

@allcontributors
Copy link

@Tommoore96

I've put up a pull request to add @Tommoore96! 🎉

@Can-Sahin
Copy link
Member

Can-Sahin commented Jul 3, 2020

Edit: Sorry I opening this back as a result of not merging the #2935 if that means anything;)

@Can-Sahin Can-Sahin closed this Jul 3, 2020
@Can-Sahin Can-Sahin reopened this Jul 12, 2020
@@ -60,6 +60,7 @@
},
"dependencies": {
"@hot-loader/react-dom": "16.11.0",
"@reduxjs/toolkit": "1.0.4",
Copy link

Choose a reason for hiding this comment

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

@reduxjs/toolkit includes redux-thunk by default. Not sure if webpack shakes-out this dependency if unused. IMO, toolkit is too opinionated (and hiding immer is too much "magic" for my taste). The ducks pattern can be implemented just as easily, and with a similar reduction in boilerplate, using a single-purpose library like redux-actions. Using redux-actions also allows easier transition to TypeScript, if desired (see typesafe-actions)

@mjtechnavious
Copy link

Is there a chance when this will be release?

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.

None yet

9 participants