question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reduce boilerplate

See original GitHub issue

Instead 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>
)

@lukejacksonn @SkaterDad @okwolf @zaceno @Alber70g

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:30 (27 by maintainers)

github_iconTop GitHub Comments

6reactions
Zhamicommented, Dec 14, 2017

I prefer the proposed view signature of ({state, actions}). The current (0.16.2) approach of double fat arrows state => actions => h() to me implies/suggests that there is an opportunity for currying, but that is not really the case.

4reactions
SkaterDadcommented, Dec 13, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found