Angular πŸ‡ΊπŸ‡¦ - practical notes
1.63K subscribers
1.6K photos
1 file
532 links
Angular - practical notes

This group is for posting practical notes for Angular developers. Mostly all posts are for quick implementation https://t.me/angular_practical_notes (Commenting on posts only in ENG and UA langs here). Welcome!
Download Telegram
πŸ“„ Tracking an inactive user using RXJS

#angular #rxjs

User inactivity can be defined as a period during which a user does not interact with the application. Tracking this inactivity helps in various scenarios, such as optimizing resource usage, enhancing security, and providing a better user experience.


// inactivity.service.ts

import { Injectable } from '@angular/core';
import { Observable, fromEvent, timer } from 'rxjs';
import { mergeMap, mapTo } from 'rxjs/operators';

@Injectable({ providedIn: 'root'})
export class InactivityService {

public trackInactivity(
duration: number
): Observable<boolean> {
const mouseMove$ = fromEvent(document,'mousemove')
.pipe(mapTo(true));

const keyDown$ = fromEvent(document,'keydown')
.pipe(mapTo(true));

return timer(0, duration)
.pipe(
mergeMap(() => mouseMove$ || keyDown$)
);
}
}



βœ… Article link: https://designtechworld.medium.com/angular-tracking-an-inactive-user-using-rxjs-in-built-and-custom-events-33d2e95fd167
πŸ”₯1
πŸ“„Managing the Sticky Navigation: Angular, Tailwind, and RxJS

#angular #rxjs #tailwind #navbar #ui_element

Explanation:
β€” `public readonly isSticky$ = fromEvent(window, 'scroll').pipe(...):` This defines the isSticky$ observable using
RxJS operators. It listens for scroll events on the window, maps them to the vertical scroll position (window.scrollY), filters out consecutive duplicate values, and then maps the scroll position to a boolean value indicating whether the scroll position is greater than 24 (assuming 24 is a threshold value for determining when the navigation bar should become sticky).

β€” `distinctUntilChanged()`: This operator filters out consecutive duplicate values emitted by the observable.

β€” `map((scrollTop: number) => scrollTop > 24)`: This operator maps the scroll position (scrollTop) to a boolean value, indicating whether the user has scrolled past a certain threshold (24 in this case).

β€” `(isSticky$ | async) === true`: This condition checks if the value emitted by the isSticky$ is true or not. Which makes it convenient since you don’t have to unsubscribe the observable.

β€” `sticky top-0 z-10 shadow-lg opacity-95 bg-white`: These classes from TailWind will help enhance the sticky experience when the users scroll down.


βœ… Article link
πŸ“„ Infinite Scroll Component in Angular

#angular #rxjs #ui_element #infiniteScroll

βœ… Article link 🎁 Code Link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“„ Internet connection monitoring in Angular

#angular #rxjs

⚠️ The example is for presentation purposes only and can be refactored.

βœ… Article link
πŸ‘1
πŸ“„ How to Replace RxJS with Signals

#angular #rxjs #signals

βœ… Article link
πŸ‘2
πŸ“„ Data fetching patterns in Angular

#angular #rxjs

The idea of the Asynchronous State Handler is to combine asynchronous operations with an explicit loading and error state. While an asynchronous operation is running, the status is loading. It ends either in an error state or with the actual result of the operation. Thinking of a generic operation result T, the Asynchronous State Handler is a function that returns T | 'loading' | 'error'. Using a union type underlines that the result is always exactly one state. Using string literal types for loading and error state is simple but descriptive. They can be replaced by other types if required.


βœ… Article link
🌐 Angular @let declarations: Smart Template Subscriptions

#angular #rxjs #shareReplay #let

βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
❀3
β™ŒοΈ Scheduler in RxJS

#rxjs #observeOn #asyncScheduler

One common scheduler in RxJS is the observeOn() operator. The observeOn() operator is used to specify the scheduler on which an observable should emit its values.

In this example, the from() function is used to create an observable that emits the values 1, 2, and 3. The observeOn() operator is then used to specify that the observable should emit its values on the async scheduler, which will cause the values to be emitted asynchronously. The asyncScheduler is a common scheduler in RxJS that schedules tasks to be executed asynchronously using setTimeout().


βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘1
β™ŒοΈ Multicasting in Angular

#angular #rxjs #share #publish #shareReplay

What is Multicasting?
Multicasting allows an observable to share its execution across multiple subscribers, so that all subscribers receive the same emitted data at the same time. By default, observables in RxJS are β€œunicast,” meaning each subscription creates a separate execution of the observable. This can lead to multiple API calls or side effects if several components subscribe to the same observable.

Multicasting ensures that only one execution occurs, regardless of how many subscribers are attached to the observable. This is particularly useful in scenarios where expensive operations (such as HTTP requests) should be shared across multiple components without being re-executed multiple times.


βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘5
πŸ€“ From RxJS to Signals

#angular #rxjs #signals

βœ… Article Link
πŸ‘7