GithubHelp home page GithubHelp logo

tstpierre / ddd-redux Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 1.86 MB

Denver Dev Day - Maintainable JavaScript apps with REDUX

License: MIT License

TypeScript 80.70% JavaScript 6.30% CSS 2.76% HTML 10.24%

ddd-redux's Introduction

ddd-redux

Denver Dev Day - Maintainable JavaScript apps with REDUX

Follow up to a question regarding when to make API calls

Reducers should remain syncronous. So you certainly should not be making an API call there. Instead, you can take this approach:

  • From your component, instead of dispatching an Action - you could call an injected Angular (in this example code base) to make the API call
  • Centralized in that service, you can use standard promise handling. in your .then you can dispatch the Action that this specific API call has completed and communicate any payload as needed; likewise dispatch any Action to denote any error occuring
  • This then runs through the pure reducers and can spit out the new state and let rxjs update the observing components
//angular service ommitted, must inject ngRedux to the service so it has the store and dispatch capability

loadCats(): void {  // you could add a loading: boolean to the state container
                    // to do some UI spinner/loading UX

    let self = this;

    psuedoCodeHttpClient.get('cat-api')
        .then((cats: Array)) => {
            // Here we can tie back the "angular way to make api calls" result
            // into the plain JS reducer and allow the state to change properly
            // and trigger observable updates

            self.ngRedux.dispatch(self.actions.catsFinishedLoading(cats));
        }
        .catch(() => { /* error action dispatch  */ }
    );
}

ddd-redux's People

Contributors

codedispenser avatar tstpierre avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

wgengarelly

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.