Code Monkey home page Code Monkey logo

amexio-redux-demo's Introduction

Redux + Angular + Amexio

Angular without Redux

SPA is great for building modern web-based applications. However as more and more applications are being transferred into the browser the complexity for managing the state of Application becomes complex.

Angular, are using a component-based approach to divide the application into smaller units. But in angular component has a logic which calls the service and set data to localised properties which is eventually used in View Template.

As a complexity of application start to increase components needs to share the data. This we achive by

  • Defining component tree structure
  • Define shared service
  • OR do event handling

Above approach works if you have application with few components, if number of components are more then you application is going to look like Spaghetti :). Some of drawbacks are

  • You start defining more input/out properties to component. Which makes components more inflexible as it is now dependent of someone else.
  • If component state is changed it needs to notify other
  • As there are lot of component dependency, data flow might become unpredicatable
  • Not easy to state the component
  • Adding new feature is goining to be time consuming

To overcome with above issue we can use Centralized application state management using Redux.

Redux

Redux is librarby which helps to manage the state of the Application. Redux is a predictable state container for JavaScript apps which makes it possible to use a centralized state management in your application.

Benifits of using Redux

  • Predicatable application state
  • Decoupled architecture
  • Application testing
  • Easy yo add new features
  • Great dev tooling
  • Single source of truth - The state of your whole application is stored in an object tree within a single store
  • State is read-only - The only way to change the state is to emit an action, an object describing what happened

When to use Redux ?

  • Multiple place having copies of same data
  • Multiple view that need to work on same data and should also be in sync
  • Multiple user updating data
  • Multiple actors updating same date

Blocks of Redux

  • Store : It is single JS object that contains state of Application. You can think store as database at client side
  • Actions : Is plain JS object that represent something happend in application
  • Reducer : It is pure function which represent how the of state application changes in reponse to the action. Reducer never modifies the state, instead it returns the new state

Installing Redux

npm install redux @angular-redux/store --save

Todo application

screen shot 2019-02-12 at 3 42 47 pm

Demo Todo application consistof three components

  • Add todo to store
  • Display all todo's from store
  • Display todo's count priority wise

Thank you!

Chers Happy learning :)

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.