Tips for studying effectively

I have just attended a “7 habits of highly effective people” course in Vietnam. The guy who taught me was amazing. He’s an alumni of NUS who founded 6 clubs and still managed to graduate with second…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Zero Boilerplate Redux

I know boiler plate in redux is well trodden ground but look at the simple app bellow.

There are a number of good reasons you may be using redux in your work. The redux dev tools and time travel debugging is a very good one. However with redux inevitably comes boilerplate which Ihope to show is unnecessary.

Using this we can

This it the secret sauce that makes it all work.

Taking the ‘Actions Map’ we map over each key and generate a new object where each key is assigned a function that generates an action and dispatches it to the redux store automatically.

The action type generated will have the key as its name i.e “increment” and the payload will be any arguments passed.

Now we can just take our generated actions object and call the function actions.increment(3) and boom. We don’t need to stop there either as using typescript we make it all typesafey and code hinty.

Because both actions and reducers are generated from the same source we don’t need a set of action type strings floating about we have to maintain. We pass the generated actions object to our connected components so its all super clean. And just like that gone is all the boilerplate.

Its all up on github

live demo here

Alright there is a bit of extra magic in the background need to make this work.

Maybe you can see the problem but I made it work so you don’t need to worry about that

How do I use multiple reducers?

Add a comment

Related posts:

The mandalas of content

A friend of mine has recently taken up coloring mandalas in her free time. She tells that it is not only a powerful relaxing tool, but also a way to reach “nirvana”, as she explains, an status in…

Topic Proposal

Does the gun possession actually protects the citizens? This topic might be a normal elderly subject, but this classic issue does not have an explicit conclusion from pro and con so far. I personally…

The famous wireframes

When you start a project, you usually follow a design process from an idea to a final concept. As already mentioned, this process don’t have to be linear, you can jump into previous steps to next…