fabiobiondi / talk-angular-rxjs-real-usecases

Source Code - RxJS: real world scenarios for Angular - Conference: CodeGen 2021

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RxJS Examples for Angular

This repository contains the source code of my live coding session "RxJS: real world scenarios for Angular".

What I did

I have written some real-world examples in which I use an idiomatic approach in RxJS for managing common scenarios in Angular applications.

This Angular project is not organized in ngModules in order to keep it as simple as possibile and to focus on RxJS


Installation

  1. Clone this repository
git clone https://github.com/fabiobiondi/talk-angular-rxjs-real-usecases.git
  1. Install dependencies
cd project_name
npm install
  1. Run project
npm start
  1. Run JSON Server (Fake REST API server)
npm run server

Examples

Following a list of examples you can find in the repository:

AUTHENTICATION EXAMPLE

File Goal RxJS topic
login.component ROUTED COMPONENT:
Example of Reactive forms with async validator
user.validators.service.ts ASYNC VALIDATOR SERVICE:
Check if username exists, handle pending and return error if not (used in login.component.ts)
timer
switchmap
auth.service.ts SERVICE:
Simulate JWT (login / logout / role / token) by using RxJS Subject to store and share data
BehaviorSubject
map
auth.interceptor.ts HTTP INTERCEPTOR:
Send token to each HTTP requests and handle errors
withLatestFrom
mergeMap
first
iif
delay
catchError
of
throwError
admin.guard.ts ROUTER GUARD:
Guard to allow access to admin sonly
(used in app-routing.module.ts)
Return Observables in router guards
if-logged.directive.ts DIRECTIVE:
Directive to render DOM when user is logged
(used in navbar.component.ts)
distinctUntilChanged
takeUntil
Subject
if-role.directive.ts DIRECTIVE:
Directive to render DOM by roleId
(used in navbar.component.ts)
distinctUntilChanged
takeUntil
Subject

OTHER EXAMPLES

File Goal RxJS topic
users.component ROUTED COMPONENT:
Multiple HTTP requests
forkjoin
map
users-details.component ROUTED COMPONENT:
Handle Observable sequence to get user details by router params
switchmap
map
activatedRoute.params
demo-async-pipe.component.ts ROUTED COMPONENT:
How to use async pipe to get the role name by using the roleId
role-name.pipe.ts ASYNC PIPE:
async pipe to get the roleName by using the roleId
timer
switchMap
map
meteo.component.ts ROUTED COMPONENT:
How to use RxJS operators in Reactive Forms
filter
debounceTime
distinctUntilChanged
switchMap
map
catchError

SOCIAL PROFILES

COMMUNITIES

About

Source Code - RxJS: real world scenarios for Angular - Conference: CodeGen 2021


Languages

Language:TypeScript 89.9%Language:JavaScript 7.9%Language:HTML 1.7%Language:CSS 0.4%