Skip to content

izaakschroeder/redux-lift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-lift

Store composition for redux.

build status coverage license version downloads

The current primary composition mechanism in redux is middleware. While useful in altering the behavior of the dispatch function, it offers little control for composing multiple parts of an application that have different action or store needs. This is where lifting is useful.

Lifting allows you to "lift" your state, reducers and actions into another context. Lifting is a kind of store enhancer that is a superset of middleware.

Indeed, the applyMiddleware function can be built trivially using lift:

import lift from 'redux-lift';

function applyMiddleware(...args) {
  // `applyMiddleware` is really just lifting the dispatch function, nothing
  // more. Everything else is the identity lift.
  return lift({ liftDispatch: compose(...args) });
}

But the real power of lifting lies in its ability to manipulate the whole state tree, not just the dispatch function. What can you do with lifting?

  • Implement time-travel for dev-tools,
  • Keep track of promises for automatic server-side rendering,
  • Track ephemeral UI state,
  • Compose multiple redux apps together.
import lift from 'redux-lift';


export default lift({

});
function TextField({ value, onChange }) {
  return <input value={value} onChange={onChange} type='text'/>;
}

// https://github.com/rackt/react-redux/blob/master/src/components/connect.js
function ephemeral(eventMap) {
  return connect(function(state) {
    return {
      value: state.ephemeral[uniqueKey]
    }
  }, function(dispatch) {
    return {
      onChange: dispatch('EPHEMERAL', uniqueKey)
    }
  });
}

export default ephemeral({
  events: {
    onChange(ev) { return { value: ev.target.value; }}
  }
})(TextField);

About

Lifting for redux.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published