β³οΈ How to Replace RxJS with Signals
#angular #rxjs #signals
β Link: https://blog.bitsrc.io/angular-16-is-out-now-learn-how-to-replace-rxjs-with-signals-c1f6f410809
#angular #rxjs #signals
β Link: https://blog.bitsrc.io/angular-16-is-out-now-learn-how-to-replace-rxjs-with-signals-c1f6f410809
π1
This media is not supported in your browser
VIEW IN TELEGRAM
β οΈ How to replace rxjs Subjects with Signals
#angular #rxjs #subject #signal
π©> Angular 16
β Article Link: https://medium.com/ngconf/handling-user-actions-with-signals-in-angular-ff40bb63e857
π Code Link: https://github.com/alfredoperez/ng-demos/blob/main/libs/demos/src/lib/demos/ngrx-with-signals/ngrx-with-signals.component.ts#LL53C15-L53C15
#angular #rxjs #subject #signal
π©> Angular 16
β Article Link: https://medium.com/ngconf/handling-user-actions-with-signals-in-angular-ff40bb63e857
Please open Telegram to view this post
VIEW IN TELEGRAM
π2
π
#angular #rxjs #animationFrameScheduler
The
β Article Link: https://priyank-bhardwaj.medium.com/reactive-ninja-harnessing-rxjs-for-angular-mastery-part-2-7091aac29d60
animationFrameScheduler example#angular #rxjs #animationFrameScheduler
animationFrameScheduler is tailored for tasks that require synchronization with the browser's animation frame. It schedules tasks to be executed just before the next animation frame, ensuring smooth animations and minimizing unnecessary computations. For instance, we can utilize the animationFrameScheduler to update the UI based on animation frames, creating a visually pleasing and responsive user interface.The
scrollPosition$ observable captures the scroll position of the window on each scroll event. The animationFrameScheduler is used to ensure that the scroll position updates and smooth scrolling effect occur right before each animation frame, providing a visually smooth scrolling experience. When the user clicks the "scroll to top" button, the scrollPosition$ observable is subscribed to, and the window is scrolled smoothly towards the top in increments of 10 pixels until the scroll position reaches 0.β Article Link: https://priyank-bhardwaj.medium.com/reactive-ninja-harnessing-rxjs-for-angular-mastery-part-2-7091aac29d60
π Custom Operators in RxJS
#angular #rxjs
β Article Link: https://medium.com/@navneetsingh_95791/custom-operators-in-rxjs-for-angular-applications-building-and-utilizing-your-own-operators-b5c281f979a1
#angular #rxjs
β Article Link: https://medium.com/@navneetsingh_95791/custom-operators-in-rxjs-for-angular-applications-building-and-utilizing-your-own-operators-b5c281f979a1
π Customizing RxJS with Your Own Operators
#angular #rxjs
β Article link: https://javascript.plainenglish.io/customizing-rxjs-with-your-own-operators-eb9094162202
#angular #rxjs
β Article link: https://javascript.plainenglish.io/customizing-rxjs-with-your-own-operators-eb9094162202
This media is not supported in your browser
VIEW IN TELEGRAM
π Simple modal in Angular
#angular #rxjs #standalone #modal #ngTemplate
β Article link: https://medium.com/@greenFlag/how-to-easily-and-quickly-create-a-modal-in-angular-a2f82d5c11f6
π Example: https://stackblitz.com/edit/stackblitz-starters-6pmxgl?file=src%2Fapp%2Fapp.component.ts
#angular #rxjs #standalone #modal #ngTemplate
β Article link: https://medium.com/@greenFlag/how-to-easily-and-quickly-create-a-modal-in-angular-a2f82d5c11f6
Please open Telegram to view this post
VIEW IN TELEGRAM
π1
π Custom RxJS operators 1/7: "Π‘ache operator"
#angular #rxjs #cache
Often an RxJS stream represents an http request β a stream that emits a single value and completes. Performance-wise, it is a good practice to cache a response from a server for a certain amount of time. The built-in share operator can be configured to provide a caching mechanism with a Time To Live (TTL) for a response.
operator
#angular #rxjs #cache
Often an RxJS stream represents an http request β a stream that emits a single value and completes. Performance-wise, it is a good practice to cache a response from a server for a certain amount of time. The built-in share operator can be configured to provide a caching mechanism with a Time To Live (TTL) for a response.
operator
import { ... } from 'rxjs';
function cache<T>(ttl: number = Infinity): MonoTypeOperatorFunction<T> {
return share({
connector: () => new ReplaySubject(1),
resetOnComplete: () => timer(ttl),
});
}π₯1
π Custom RxJS operators 2/7: "filterNil operator"
#angular #rxjs #filterNil
It is quite common to filter out null and undefined values from the resulting stream. Obviously, the built-in filter operator is the right tool to do the job, however in order to ensure proper type narrowing, the predicate function has to be a user-defined type guard. Therefore, it makes sense to encapsulate it into a custom RxJS operator.
operator
#angular #rxjs #filterNil
It is quite common to filter out null and undefined values from the resulting stream. Obviously, the built-in filter operator is the right tool to do the job, however in order to ensure proper type narrowing, the predicate function has to be a user-defined type guard. Therefore, it makes sense to encapsulate it into a custom RxJS operator.
operator
import { filter, OperatorFunction } from 'rxjs';
function filterNil<T>(): OperatorFunction<T, NonNullable<T>> {
return filter((v): v is NonNullable<T> => v != undefined);
}π1π₯1
π Custom RxJS operators 3/7: "firstMatching operator"
#angular #rxjs #firstMatching
For most use cases, the task can be accomplished at least in two ways. However, there is a subtle difference when the source stream completes without having emitted a value that meets requirements. The detailed explanation can be found in one of my RxJS hints. The operator in question allows to choose a given strategy to handle such scenario based on the required argument.
operator
#angular #rxjs #firstMatching
For most use cases, the task can be accomplished at least in two ways. However, there is a subtle difference when the source stream completes without having emitted a value that meets requirements. The detailed explanation can be found in one of my RxJS hints. The operator in question allows to choose a given strategy to handle such scenario based on the required argument.
operator
import { of, MonoTypeOperatorFunction, pipe, first, filter, take } from 'rxjs';
function firstMatching<T>(
predicateFn: (v: T) => boolean,
required: boolean = false
): MonoTypeOperatorFunction<T> {
return required ? first(predicateFn) : pipe(filter(predicateFn), take(1));
}π₯1
π Custom RxJS operators 4/7: "
#angular #rxjs #withLifecycle
Debugging RxJS code can be a challenge. Fortunately, the built-in tap operator provides a way to track lifecycle events for a stream.
operator
withLifecycle operator"#angular #rxjs #withLifecycle
Debugging RxJS code can be a challenge. Fortunately, the built-in tap operator provides a way to track lifecycle events for a stream.
operator
export function withLifecycle<T>(
streamId: string
): MonoTypeOperatorFunction<T> {
return tap({
subscribe: () => console.log(`[${streamId}]: subscribed`),
unsubscribe: () => console.log(`[${streamId}]: unsubscribed`),
finalize: () => console.log(`[${streamId}]: emitted final value`),
});
}
β€1