react-slingshot icon indicating copy to clipboard operation
react-slingshot copied to clipboard

Switch Redux logic setup to use Redux Toolkit

Open markerikson opened this issue 4 years ago • 4 comments

Hi, I'm a Redux maintainer. I'd like to offer a couple suggestions.

Is your feature request related to a problem? Please describe.

The current Redux example implementation shows use of reducers with "hand-written" immutable update logic, and has a somewhat complex store configuration. In addition, the project currently uses a "folder-by-type" folder structure.

Describe the solution you'd like

The project should switch to using the official Redux Toolkit package to implement the Redux logic.

The project should also consider switching to a "feature-folder" or "ducks" folder structure, rather than a "folder-by-type" structure.

Additional context

Redux Toolkit is our new official, opinionated, batteries-included toolset for efficient Redux development. It includes utilities to simplify several common Redux use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state at once without writing any action creators or action types by hand.

We are recommending RTK as the default standard way to write Redux logic. Partly related to that, we are also recommending that developers should prefer to use "feature folders" or "ducks" rather than "folder-by-type". (Reference: the work-in-progress Redux "Style Guide" docs page.)

Since many developers will be starting their projects using react-slingshot, it would be beneficial if Redux Toolkit was included as part of the default project setup, as it will greatly simplify the application code they write.

markerikson avatar Nov 18 '19 00:11 markerikson

Thanks for opening this issue Mark and thanks for all that you’ve done in Redux land.

I’m definitely down with this, but, It’d be good to get @coryhouse and @kwelch chime in on this as well.

nickytonline avatar Nov 18 '19 01:11 nickytonline

FWIW, I've cloned the repo and am currently playing around with trying to do the conversion.

Honestly, the biggest problem atm appears to be the heavy reliance on import * as ActionTypes from '../constants/actionTypes'; in store.spec.js :)

Switched out the store config only took me about 5 minutes. I may just try adding an equivalent features/fuel/fuelSlice.js file for point of comparison, rather than trying to port all the logic and the tests.

markerikson avatar Nov 18 '19 01:11 markerikson

Another point in favor of switching to RTK: the current setup adds redux-thunk and redux-immutable-state-invariant, which RTK already adds to its store setup by default.

markerikson avatar Nov 18 '19 01:11 markerikson

PR is up. I made some additional stylistic-ish changes. I'd appreciate it if you'd consider them, but you may ignore them if desired.

Also, there's some prior discussion on the folder structure at #146 .

markerikson avatar Nov 18 '19 01:11 markerikson