Angular 2 Application Architecture

  • We will go over the following topics:

    The challenges of building large scale single page apps
    Three types of state in an app
    The Flux architecture
    The Redux state container
    The advantages of immutable state
    Immutable.js and immutable data collections
    Building a Flux Angular 2 app step by step
    How to use Immutable.js and still keep type-safety
    Conclusions

    The most important question about this type of architecture is probably when should we use it and why?

  • Actions are dispatched directly against the store

    Building an Angular 2 App using Flux

    Let’s build a simple app (available on this repository), that looks like this:

    Notice that the app state is logged in the console.

  • For example the Todo App has the following state:

    We can see the state is separated into two parts:

    the application data, under property todos
    the global Ui state, under property uiState

    Creating a Redux Action

    Now let’s define some application actions.

  • Creating a Redux reducer

    For example this is the reducer for the application data state:

    The reducer just branches the calculation of the new state and delegates it to other functions, or calculates the new state directly in the switch statement if that only takes a couple of lines.

  • The store can now be injected in any component, and used to dispatch actions:

    Immutable.js and immutable data collections

    There are no real benefits for storing state inside a store using Redux if we cannot make the state immutable in a practical way.

In this post we will explore how to design an Angular 2 application according to the Flux architecture, by using the Redux and Immutable.js libraries. We will go over the following topics:
Continue reading “Angular 2 Application Architecture”

Prashant Abhishek’s response to What are the best resources to get started with ReactJS coming from an AngularJS background?

  • The tutorial is good enough to give you a good sense of what React is all about and how it is actually used then you can look into best practices of React.
  • Frontend tooling is not specific to React but its definitely a considerable part of building a real world project in React.
  • This tiny book explains popular choices and a series of posts by Tyler McGinnis uses gulp and browserify while walking through building an app in React.
  • Here’s a tutorial by @sandeep on how to build isomorphic javascript web apps with Alt.
  • I have two collections Learn React and Learn Flux, which I keep updating whenever I find something interesting in React and Flux world.

What are the best resources to get started with ReactJS coming from an AngularJS background?
Continue reading “Prashant Abhishek’s response to What are the best resources to get started with ReactJS coming from an AngularJS background?”

Start 2017 with 7 Awesome Online Courses

  • This course will get you up and running quickly, and teach you the core knowledge you need to deeply understand and build React components and structure applications with Redux.
  • This course will get you up and running quickly, and teach you the core knowledge you need to deeply understand and build Webpack-based projects.
  • This course will get you up and running with React Native quickly, and teach you the core knowledge you need to deeply understand and build React components for mobile devices.
  • This course will get you up and running with MongoDB quickly, and teach you the core knowledge you need to deeply understand and build apps centered around Mongo.
  • And if you don’t know the two mentioned Frameworks: That’s fine, too, this Course does not expect any knowledge of any other Frontend Framework – you will learn it all throughout this Course!

Are you ready to get a head start on 2017? To kick off another great year, we have hand-picked a few online courses with discounts just for you.
Continue reading “Start 2017 with 7 Awesome Online Courses”

Start 2017 with 7 Awesome Online Courses

  • This course will get you up and running quickly, and teach you the core knowledge you need to deeply understand and build React components and structure applications with Redux.
  • This course will get you up and running quickly, and teach you the core knowledge you need to deeply understand and build Webpack-based projects.
  • This course will get you up and running with React Native quickly, and teach you the core knowledge you need to deeply understand and build React components for mobile devices.
  • This course will get you up and running with MongoDB quickly, and teach you the core knowledge you need to deeply understand and build apps centered around Mongo.
  • And if you don’t know the two mentioned Frameworks: That’s fine, too, this Course does not expect any knowledge of any other Frontend Framework – you will learn it all throughout this Course!

Are you ready to get a head start on 2017? To kick off another great year, we have hand-picked a few online courses with discounts just for you.
Continue reading “Start 2017 with 7 Awesome Online Courses”

Tips For a Better Redux Architecture: Lessons for Enterprise Scale

  • Redux (paired necessarily with React-Redux) is a great benefit for medium-to-large applications because it offers a convention for how data is fetched, consumed, passed from one component to another, and ultimately displayed in the UI.
  • With Redux handling the updates to the global application state React can focus wholly on presentation and the handling of user events through props alone.
  • The reason why Redux is used instead of local, ad-hoc changes within the presentation layer or some other centralized store where accessors can mutate state (like MobX, e.g.) is because these systems can inevitably leave data flow inconsistent across the application design translating to longer ramp-up time and more difficulty debugging.
  • Instead, action creators are used exclusively to post updates to the state so that components can remain totally agnostic to state schema design:

    The immediate benefit of constructing an application this way is the certainty that every component and its data flow is architected the exact same way.

  • The idea is to keep the application as decentralized as possible by allowing each Module to be responsible for its own feature requirements while at the same time keeping its data in the global store.

So you’ve decided to try out Redux as your application state manager. Or perhaps you’re investigating better options. Good for you. With Redux the good new.
Continue reading “Tips For a Better Redux Architecture: Lessons for Enterprise Scale”

Seamless-Immutable: An Alternative to ImmutableJS

  • We used the following criteria to inform our decision:

    We found that seamless-immutable better aligned with what we were looking for in an immutability solution than ImmutableJS.

  • While a runtime exception isn’t the perfect answer to enforcing immutability, it at least gives us the guarantee that our immutable data will never change.
  • If the array that you give to is a seamless-immutable array you’ll get a runtime exception because Angular is trying to add $$hashKey to it behind the scenes.
  • While that was a frustrating discovery, it’s unfair to fault seamless-immutable for Angular’s quirks and you can simply call on your immutable array to convert it to a mutable Javascript array.
  • We defined the criteria for an acceptable immutability solution and seamless-immutable came out on top.

We’re using Redux on a project at work and a couple of months ago we decided it was time to ditch Object.assign and the spread operator in favor of an actual…
Continue reading “Seamless-Immutable: An Alternative to ImmutableJS”

Tips For a Better Redux Architecture: Lessons for Enterprise Scale

  • Redux (paired necessarily with React-Redux) is a great benefit for medium-to-large applications because it offers a convention for how data is fetched, consumed, passed from one component to another, and ultimately displayed in the UI.
  • With Redux handling the updates to the global application state React can focus wholly on presentation and the handling of user events through props alone.
  • The reason why Redux is used instead of local, ad-hoc changes within the presentation layer or some other centralized store where accessors can mutate state (like MobX, e.g.) is because these systems can inevitably leave data flow inconsistent across the application design translating to longer ramp-up time and more difficulty debugging.
  • Instead, action creators are used exclusively to post updates to the state so that components can remain totally agnostic to state schema design:

    The immediate benefit of constructing an application this way is the certainty that every component and its data flow is architected the exact same way.

  • The idea is to keep the application as decentralized as possible by allowing each Module to be responsible for its own feature requirements while at the same time keeping its data in the global store.

So you’ve decided to try out Redux as your application state manager. Or perhaps you’re investigating better options. Good for you. With Redux the good new.
Continue reading “Tips For a Better Redux Architecture: Lessons for Enterprise Scale”