TopGit theo dõi erikras/ducks-modular-redux trên GitHub, đã đạt 9.5k sao. A proposal for bundling reducers, action types and actions when using Redux
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
I find as I am building my redux app, one piece of functionality at a time, I keep needing to add {actionTypes, actions, reducer} tuples for each use case. I have been keeping these in separate files and even separate folders, however 95% of the time, it's only one reducer/actions pair that ever needs their associated actions.
To me, it makes more sense for these pieces to be bundled together in an isolated module that is self contained, and can even be packaged easily into a library.
MUST have action types in the form npm-module-or-app/reducer/ACTION_TYPE
MAY export its action types as UPPER_SNAKE_CASE, if an external reducer needs to listen for them, or if it is a published reusable library
These same guidelines are recommended for {actionType, action, reducer} bundles that are shared as reusable Redux libraries.
Name
Java has jars and beans. Ruby has gems. I suggest we call these reducer bundles "ducks", as in the last syllable of "redux".
Usage
You can still do:
import { combineReducers } from 'redux';
import * as reducers from './ducks/index';
const rootReducer = combineReducers(reducers);
export default rootReducer;
You can still do:
import * as widgetActions from './ducks/widgets';
...and it will only import the action creators, ready to be passed to bindActionCreators().
Actually, it'll also import default, which will be the reducer function. It'll add an action creator named default that won't work. If that's a problem for you, you should enumerate each action creator when importing.
There will be some times when you want to export something other than an action creator. That's okay, too. The rules don't say that you can onlyexport action creators. When that happens, you'll just have to enumerate the action creators that you want. Not a big deal.
Run cry --help to check more info about the generators available;
Implementation
The migration to this code structure was painless, and I foresee it reducing much future development misery.
Although it's completely feasable to implement it without any extra library, there are some tools that might help you:
extensible-duck - Implementation of the Ducks proposal. With this library you can create reusable and extensible ducks.
saga-duck - Implementation of the Ducks proposal in Typescript with sagas in mind. Results in reusable and extensible ducks.
redux-duck - Helper function to create Redux modules using the ducks-modular-redux proposal
modular-redux-thunk - A ducks-inspired package to help organize actions, reducers, and selectors together - with built-in redux-thunk support for async actions.
molecular-js - Set of utilities to ease the development of modular state management patterns with Redux (also known as ducks).
ducks-reducer - Function to combine ducks object reducers into one reducer (equivalent to combineReducers), and function ducks-middleware to combine ducks object middleware into one single middleware compatible with applyMiddleware.
simple-duck - Class based implementation of modules system, inspired by ducks-modular-redux. All OOP benefits like inheritance and composition. Support combining of duck-module classes and regular reducer functions using combineModules function.
Please submit any feedback via an issue or a tweet to @erikras. It will be much appreciated.
erikras/ducks-modular-redux có 9.5k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/erikras/ducks-modular-redux. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
erikras/ducks-modular-redux có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho erikras/ducks-modular-redux. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
erikras/ducks-modular-redux còn đang phát triển không?
Commit gần nhất trên erikras/ducks-modular-redux là 4.8 năm trước (theo timestamp GitHub). Repo có 336 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
erikras/ducks-modular-redux là gì?
erikras/ducks-modular-redux (erikras/ducks-modular-redux) là dự án JavaScript trên GitHub. Theo mô tả gốc: A proposal for bundling reducers, action types and actions when using Redux
erikras/ducks-modular-redux viết bằng ngôn ngữ gì?
erikras/ducks-modular-redux chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc ducks-modular-redux có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về ducks-modular-redux.