Comments (5)
Not sure what benefit variadic parameters add here, what's being passed exactly - an array of strings or an array of string arrays?
from rdx.
Array of strings. What benefit would you have in mind? I though this would allow calling the reducer with a variable number of arguments. reduce(foo)
, reduce(foo, bar)
, etc.
from rdx.
That's not really a benefit - the intent is that each reducer function does a single type of update, handling a single action, not that it acts as a top level reducer expecting varying types of action which it then has to inspect to decide how to handle (that's the Redux way of working).
What you likely need are separate functions for each distinct action and they will then provide the dispatch functions to use, again, with the parameters specific to each.
A parameter could still be optional in theory but I can't think of any use-case that makes sense off-hand.
from rdx.
I think you misunderstood my intent. Here's a little more tangible example, simple reducer to append a varying number of items to a collection
function push(state, ...newItems: string[]) {
return {
...state,
items: [ ...state.items, ...newItems ],
}
}
I check now that it actually does not work and only the first argument passed to dispatch is forwarded to the reducer.
On the other hand an optional parameter, while I have not had such a need yet, could make sense indeed and also suffers a similar issue with the inferred type for the dispatcher interface. Off the top of my head would be something like dispatch.loadingFailed(error)
where the error
is possibly undefined. That, however, can be handler by typing the reducer just slightly differently
-loadingFailed(state: State, error?: Error)
+loadingFailed(state: State, error: Error | undefined)
This works unless one would desire to call this without parameter indeed.
from rdx.
You could use the following to achieve what you want:
push(state, items: string[]) {
return {
...state,
items: [ ...state.items, ...items ],
}
}
from rdx.
Related Issues (11)
- Docs home page poor contrast when OS uses dark mode
- Cannot run tests with mocha
- Rename ModelStore method `dispatch` to `getDispatch` HOT 1
- Need docs: IntelliSense (code completion) may break on arrow functions
- Garbage collection when using the router HOT 4
- connect API for Svelte
- How to programmatically navigate to another page? HOT 1
- Integrate rdx-model with rdx HOT 2
- Plugins dispatch is never inferred
- Dark and light mode with switch HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rdx.