Angular pure pipe
34.1 هزار بار بازدید -
6 سال پیش
-
In this video we will
In this video we will discuss
1. What is a pure pipe
2. Why is it not recommended to use pipes to filter and sort data in Angular
Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
/ @aarvikitchen5572
Text version of the video
csharp-video-tutorials.blogspot.com/2018/05/angula…
Slides
csharp-video-tutorials.blogspot.com/2018/05/angula…
Angular CRUD Tutorial
• Angular CRUD tutorial
Angular CRUD Tutorial Text Articles & Slides
csharp-video-tutorials.blogspot.com/2017/12/angula…
All Dot Net and SQL Server Tutorials in English
youtube.com/user/kudvenkat/playlists?view=1&sort=d…
All Dot Net and SQL Server Tutorials in Arabic
youtube.com/c/KudvenkatArabic/playlists
This is continuation to Part 47, please watch Part 47 from Angular CRUD tutorial before proceeding.
In Angular, there are two categories of pipes
1. Pure Pipes
2. Impure Pipes
When you create a new pipe, it is pure by default. To make a pipe impure, set it's pure flag to false. Impure pipes can significantly affect the performance of the application. So you have to think very carefully, before you use an impure pipe in your angular application. We will discuss impure pipes and why they are bad from performance perspective in our next video.
@Pipe({
name: 'employeeFilter',
pure: false
})
export class EmployeeFilterPipe implements PipeTransform {
Pure pipe
1. Is fast
2. Angular executes a pure pipe only when it detects a pure change to the input value
3. A pure change is either a change to a primitive input value (String, Number, Boolean) or a changed object reference (Array, Date, Object)
4. A pure pipe is not executed if the input to the pipe is an object and only the property values of the object change but not the reference
Why are Pure pipes fast
1. An input for a pipe can either be a value type (String, Number, Boolean etc) or a reference type (like Array, Date, Object etc.)
2. If the input to the pure pipe is a value type. Since value types store data directly in the memory slot comparing if a value type value has changed is very quick.
3. On the other hand, if the input to the pure pipe is a reference type, it is executed only if the reference of the input object has changed. Checking if an object reference has changed is much faster than checking if each of the object individual property values have changed.
So pure pipes are fast, but using them for filtering data is not a good idea because, the filtering may not work as expected if the source data is updated without a change to the object reference.
One way to make this work is by making the pipe impure. Impure pipes can significantly impact the performance of the application as they run on every change detection cycle.
We will discuss impure pipes and the performance impact they can have in our next video.
6 سال پیش
در تاریخ 1397/02/17 منتشر شده
است.
34,164
بـار بازدید شده