Sébastien Lucas / Dev wiki
  • Blog Wiki
  • Story book
  • Developers comics
  • Angular
    • Angular CLI + Angular.json
    • ngTemplateOutlet
    • Angular Schematic
    • Interceptor
    • Micro frontend + Mono repo
    • Build a library module
    • Error handling
    • Virtual and infinite scroll
    • Angular i18n
    • Debug Angular
    • Angular LifeCycle Hook
    • Nested forms in Angular
    • Angular Recipes
    • Master component in Angular
    • Perfomance optimization
    • Service Workers + PWA
    • Mobile
    • Electron app / Desktop app
    • Unit test & Angular
      • Unit test recipes (Jasmine / Karma / Angular)
      • Testing services with httpMock
    • Communication between components
    • Angular snippet library
    • Release and version management
    • Angular tutorial selection
    • UI components libraries
    • Angular libraries
    • Angular Tutorials
    • NGRX
      • Angular NGRX / Tips and code examples
      • Angular new Redux (alternative to ngrx)
      • NGRX unit test
      • Angular ngrx / Basics
    • Angular 2/Angular 1 differences
  • Graphql
  • Three.js
  • Ag grid
  • Open source BIM and 3D
  • Javascript
    • Null vs undefined
    • Html API
    • Await API
    • Debug memory leaks
    • Offline and PWA
    • Javascript tutorials
    • Javascript recipes
    • Bluebird missing docs
    • Alternative to lodash with ES6
    • ES6 syntax the best parts
    • Vanilla JS
  • RXJS
    • Docs
    • Recipes
    • Mock API and sandbox
    • Observables rxjs recipes
    • Combination operators
  • NODE.js
    • Environment variables
    • Fix CORS
    • Pagination requests in API
    • API tests
    • Node.js security
    • Learn node.js
    • Best libraries for node.js
    • Mongoose recipe
    • Debug node.js
  • Gatsby / React
    • Hooks
    • React concepts
    • Gatsby internationalisation
  • Ghost blog
  • Services for developers
    • SaaS images services
    • Airtable API examples
  • MISC
    • JIRA debugging
    • Wordpress plugins
    • Interview Sébastien Lucas
    • English expression
    • True recipes
    • Science podcast
  • AI
    • Machine learning open source
    • Tensor flow
    • Machine learning
    • Code examples
    • Courses and tutorials
    • Datasets
    • The Future of AI
    • Learn algo and data structures
  • Typescript
    • Generic types
    • Typescript recipes
    • Advanced types
      • Conditional types
      • Type guards
    • d.ts files
  • Docker
    • Starting with docker
    • Dockerise simple node app
    • Docker by aymen el amri
  • Mongodb
    • Pattern and data modeling
  • Devops
    • Heroku
    • Scaleway
    • Github template
    • Gitlab CI
    • http2
    • nginx
    • zsh
    • CI Continuous integration
    • DNS
    • Devops resources
    • Gcloud useful commands
    • Authenticate Gcloud
    • Documentation generators
    • Firebase database
  • Developers ressources
    • Online platform coding
      • Online courses
      • Coding games
      • Coding test platforms
      • Links to check
    • Good developers blogs
    • Nice open source project / github
  • Tooling
    • The chrome urls
    • Linux Mac tips
    • Webstorm configuration
    • Develop in Windows
    • Mac debug hardware
    • Mac Setup for a developer
    • Chrome extension
    • Develop toolbox
  • HTML / CSS
    • Tailwind
    • Css grid
    • ☘️Nice styles & generators
    • Favicon
    • Flexbox grid
    • Flexbox layout
    • PUG templates tips
    • Html and css references
    • Css snippets
    • SASS-CSS libraries
    • New things in scss
    • SASS best practices
    • Style lint
  • Tests
    • Cypress
      • Learn cypress and more tests
      • Cypress commands
      • Cypress plugins
      • Page object && app actions
      • Flaky tests
    • Mobile test
    • BDD + Cucumber
    • Puppeteer
    • Type of tests + Ressources
    • Jasmine test
    • Mock, fake, stub in unit tests
    • E2e tests with protactor
    • Mocha
  • REVIT & AEC tools
  • Git
    • Git commits
    • Git tips
    • Git hooks
    • Set up a mono repo
  • Design Pattern
    • Functional Programming
  • Job board / Remote jobs
  • SVG
  • JSON
  • Github
    • Forking a github repo
  • NPM
    • Private NPM packages
    • Publish to NPM with np
  • Yarn
    • Yarn evolution / 2, 3...
    • Yarn Linking
Powered by GitBook
On this page
  • What it is?
  • Links to start with
  • NGRX Selector
  • Go further / More specific articles
  • Reading blog university tutorial notes
  • What to install
  • NGRX terminology
  • Who call the reducer function
  • Ngrx Dev tools

Was this helpful?

  1. Angular
  2. NGRX

Angular ngrx / Basics

PreviousNGRX unit testNextAngular 2/Angular 1 differences

Last updated 5 years ago

Was this helpful?

What it is?

Redux is a way to store in a centralized place data so that all the app can update flawlessly by subscribing to some events. For example if a component need to listen updates of "projects" content, he gets informed when this event occurs.

Links to start with

  • Angular 2 and Redux simplified

  • There is a official to get a global view on a ngrx based application

  • Other on how he setup Redux in an angular 2/4 project.

  • in this tuto Hristo Georgiev explain how to use redux in the context of angular 4 to control not only data but also UI like window resizing, hide/display of element.

  • A gist with detailed information to learn ngrx store an understand the difference with more classical way of doing it. very detailed with clear code examples.

  • Step by step example of uses of the main ngrx concepts (store, reducer, selector...)

NGRX Selector

Selectors allow you to select part of the state to display it in component

Go further / More specific articles

  • Errors not to be done with NGRX

Reading blog university tutorial notes

  • The tuto start with a description of the facebook counter bug that initiated the switch to a redux like architecture for Facebook homepage.

  • Notion of viewModel which is the derivation of a model for the display purpose of a view.

  • The transformation from view to view Model is done via a function called a Selector - the input of a Selector is the Model, and the output is the View Model

  • the data is stored as a map rather that an array (optimized for by id query (same way firebase used))

Example map

  • In the store we store both application model and UI state and user preference...

What to install

npm install @ngrx/store @ngrx/store-devtools @ngrx/router-store-builds @ngrx/effects --save

Trigger an error is state is not correctly cloned in the reducer

npm install ngrx-store-freeze --save-dev

you should then have in your package.json something like

NGRX terminology

  • store: the shared service managed by the ngrx library that manage state and trigger event when the state is changed

Store could be thought as the database in the store as a database analogy.

  • state: Global object that store all global values stored in the store. Each feature module add a property to the store to make available the useful part of the global state

  • The reducer is the thing that catches and handles the actions that are dispatched from your smart components (or from your action reducers), and it is also the thing that actually resets the state to a new, modified state.

Reducer could be thought as the database table in the store as a database analogy.

  • selector: function that in charge to retrieved view model structure that are data as need by the UI.

Selector could be thought as the query in the store as a database analogy.

  • action: an action triggered by the user like clicking on a button, changing view that impact the global state. Action can be loading of data, for example The data have just finished loading, we trigger an action.

    Practically the purpose of an action file is the set the string identifier of an action MY_AWESOME_ACTION and set the type of the payload of the actions (passed to the effects)

  • effect: a change to do when an action is triggered

  • entity:

Who call the reducer function

Every times an action is triggered can be

  • the router action

  • ngrx special action at initialization

Ngrx Dev tools

The raw tab or tree tab allow navigating in the state values

  • reducer the table

The main component (but not obligatory) to install the architecture. For example, you can use actions and effects without to the store

redux store architecture

Tools integrated with the chrome extension to debug ngrx powered application

integration with the angular router

Side effects.... (there is a different version for angular 2 and 4)

But since 4 version all those packages are put in . Installing each libs separately is though still needed.

reducer: main function where is defined the logic : (could be thought as the database tables). Practically the reducer have the role to merge / save the state modification with the state global state. Another :

Reducer are a type of function in programation, that work on a collection of object and produce a final unique object by running function at each loop turn. A very clear definition and examples are available in this .

the store the database as explained

https://medium.com/beautiful-angular/angular-2-with-redux-using-ngrx-store-2f93a8ad0dd
demo / starter app
Demo app of angular + redux
Tuto about ngrx for angular 2-4 by angular university why use it + a concrete example
heavily commented main reducer of ngrx demo app
UI state management with Redux in angular 4
Setting up ngrx
Comprehensive Introduction to @ngrx/store
https://kimsereyblog.blogspot.fr/2017/07/managing-global-state-with-ngrx-store.html
Understanding ngrx selector
More in depth article on what is a selector
http://brianflove.com/2017/11/01/ngrx-anti-patterns
understanding the [] for ngrx action type
Get state in effects
Library of ngrx pattern by Victor Savkin
store
store dev tools
router store
effects
one github repository
explanation
ngrx tutorial
Link to utility functions createSelector or createFeatureSelector
comment of example app book reducer