Skip to content

davelosert/di-with-redux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dependency Inversion with Redux

This repository shows how to easily decouple your apps business logic from details like your API using the dependency inversion principle in redux with redux-thunks. The full explanation will be in a blog post which I will link here as soon as I published it.

How it works

This app can easily be started in two different modes:

The latter script simply sets an environment-variable which in turn will make webpack pass it to the Application via the DefinePlugin. The Application then decides based on that Variable which Implementation of the TodoRepository-Interface (Mock or HTTP) it will pass as a third argument to all redux-thunks.

Since the thunk now only needs a dependency to the TodoRepository-Interface, it is decoupled from where the data is actually coming from, therefore adhering to the Simple Responsibility Principle as well (as we decoupled the App-State-Control from the Data-Loading).

In other words: It decoupled the apps business logic from the API-Details.

This gives us several advantages:

  • The App can be developed without a Internet Connection
  • We don't have to wait for the implementation of the API to implement new features or simulate certain behaviours
  • If the API changes, you will only have to change one service - not your App
  • It would be very easy to add new ways for Data-Loading, e.g. LocalStorage, HTTP2, Websockets etc.

About

Example how to do dependency inversion with redux - used for a blog post

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published