Reduce boilerplate
See original GitHub issueInstead of changing the API #484, let’s approach and try to come up with a solution for the boilerplate problem within the current architecture.
Importing/Exporting modules
// ABC.js
import { B } from "./B"
import { C } from "./C"
export const state = {
value: 0,
B: B.state,
C: C.state
}
export const actions = {
add: value => state => ({ value: state.value + value }),
B: B.actions,
C: C.actions
}
Setup
import { A } from "./A"
import { B } from "./B"
import { C } from "./C"
app({
state: {
A: A.state,
B: B.state,
C: C.state
},
actions: {
A: A.actions,
B: B.actions,
C: C.actions
}
})
Props
const view = state => actions => (
<App>
<Feed state={state.feed} actions={actions.feed} />
<Trend state={state.trend} actions={actions.trend} />
</App>
)
// OR
const view = state => actions => (
<App>
<Feed
model={{
...state.feed,
...actions.feed
}}
/>
<Trend
model={{
...state.trend,
...actions.trend
}}
/>
</App>
)
Issue Analytics
- State:
- Created 6 years ago
- Comments:30 (27 by maintainers)
Top Results From Across the Web
Reducing Boilerplate - Redux
Redux reduces the boilerplate of Flux stores considerably by describing the update logic as a function. A function is simpler than an object, ......
Read more >Three ways to reduce the Redux boilerplate (and ... - Jakob Lind
Three ways to reduce the Redux boilerplate (and become more productive) · 1. Fewer files when using Ducks · 2. You don't have...
Read more >Reduce boilerplate with Redux Toolkit - Medium
You will have to write a lot less boilerplate code. Writing actions and reducers way more easy. Avoid adding many other libraries for...
Read more >How To Reduce Your Tests Boilerplate | by Alon Yehezkel
Reducing extra information and boilerplate can be done in many ways. One of them is to use test drivers which hold implementation details...
Read more >What are your favorite tools/tricks to reduce boilerplate code?
Actually, speaking of code generation, using code generation techniques you can boil away the boilerplate code. SO, for example, if you use Spring...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I prefer the proposed view signature of
({state, actions})
. The current (0.16.2) approach of double fat arrowsstate => actions => h()
to me implies/suggests that there is an opportunity for currying, but that is not really the case.This is definitely a nice incremental improvement!
I’m voting for changing the view signature also. Dont really care which of the 2 proposed solutions, they’re both nicer.