GithubHelp home page GithubHelp logo

redux-lift's Introduction

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

redux-lift's People

Contributors

izaakschroeder avatar

Stargazers

Andrey Frolov avatar Razvan Ioan Puscasu avatar Vitaly Blinovskov avatar Thomas Payne avatar Mike Davis avatar Aldiantoro Nugroho avatar Yurii Rashkovskii avatar Chris Fothergill avatar Brad Pillow avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

10xjs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.