Giter Club home page Giter Club logo

reduxish's Introduction

Reduxish

Two of my biggest challenges with Redux are:

  1. creating multiple copies of the same component without having namespace collisions

  2. the decoupling of where a components state lived in the global state and having to connect that component to the global state.

Well, long story short, here's a potential solution that solves both of these issues. It's basically the Elm 0.16 Architecture without being so rigorously functional.

Basically, you define static methods on your component classes for initand reducer. Each component also gets dispatch and state as props. Then you can wrap and unwrap actions while composing the initial state and reducers in order to namespace each component.

There are 4 examples which are grouped in src/index.js. Uncomment only one block to run that example. To get it running, just run npm install && npm start.

This example is also specific using redux-thunk middleware -- check out how wrapAction works in src/utils.js.

The biggest trade-off to this approach over vanilla Redux is that every component now has strict encapsulation. That is, actions are no longer global. So if you import a component and dispatch one of it's actions, it's likely that nothing will happen because that component's state / action namespace might not be top-level. But that all makes sense because the problem we were trying to solve in the first place is that we couldn't render multiple independent copies of a single component!

reduxish's People

Contributors

ccorcos avatar

Stargazers

Saadh avatar Dave Churchill avatar RYeah Sh avatar John Lindahl avatar Vlad Trukhin avatar Rikard Gehlin avatar Vladimir Starkov avatar Fabio Oliveira Costa avatar Ahmet Simsek avatar Sergey Lukin avatar Devon Zuegel avatar Ricard Solé avatar Mikey avatar Fabian Eichenberger avatar Vitaly Blinovskov avatar Syrus Akbary avatar

Watchers

James Cloos avatar  avatar  avatar

reduxish's Issues

async init

Hello
I really like your demo-app and I am trying to reuse a lot of the code in my project. What I am struggling with though, is that I try to adapt it to work with an async version of init-functions but I just don't get it to work, preferably reusing the actions themselves.
e.g: fetching some weather data already in the init-function in the https://github.com/ccorcos/reduxish/blob/master/src/Weather.js

My target is to be able to use the static init function(s) to be able to fetch data on the server before server side rendering and then just passed the hydrated state to the SSR. While at the same time not have to repeat the data-fetching code, once specifically for SSR and one for client-mounted components.

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.