What is the reason for Angular's Change Detector avoiding the use of Proxy objects?

Angular, specifically through zone.js, applies patches to functions like setTimeout(), event listeners, and more. This is done to trigger the Change Detector when the respective callbacks are executed. However, Angular faces the challenge of not knowing which objects have been updated and which remain unchanged. As a result, Angular has to check every property used in the template to determine if it has changed or not, making this approach less efficient.

So, my question is: Why doesn't Angular utilize Proxy objects for this purpose? By using Proxy objects, Angular would be able to precisely identify what has been changed without needing to compare the entire state tree. Is there a specific reason why Angular developers opted against incorporating Proxy objects (as seen in Vue)?

On a side note, one key advantage of using a Proxy object could be the ability to call functions within templates without triggering additional or unnecessary Change Detection cycles:

<div *ngFor="let item of myFunction()">...</div>

Answer №1

Embracing observables is a more elegant solution to avoid constantly checking everything with each change in Angular.

By consistently using observables with the async pipe, Angular will effortlessly track changes and updates without the need for complex proxies or similar workarounds.

If you design your services and pages to solely return observables, your code will be exceptionally clean and allow for seamless integration into HTML.

In addition, it's recommended to disable polling when relying on observables exclusively, although I can't recall where this setting is located at the moment (it’s been some time).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unusual data structure found in firestore database

My Firestore data is structured like this: Timestamp(seconds=1566840930, nanoseconds=491000000) Since it's not a valid Unix timestamp, I'm unsure how to display it in a more readable format, like dd.mm.yy. The component where I fetch the data ...

What is the method for adding local images to FormData in Expo version 48 and above?

When working with Expo v47 and its corresponding React Native and TypeScript versions, FormData.append had the following typing: FormData.append(name: string, value: any): void An example of appending images using this code could be: const image = { uri ...

How can I detect when the Redux state object in my Angular (v5) application changes?

Can someone please explain to me the process of creating a listener, like subscribing to the AppState changing? Here is the basic service I currently have. In my view, there is a dispatch action that increments the counter. After the counter changes valu ...

A button paired with a selection menu for a seamless user experience

One interesting feature I have implemented is a dropdown that filters records on an HTML table without the need for a button. The filter functionality works flawlessly even without a button to confirm the selection. public selectedBrand: any; public onCha ...

Creating a personalized data filtering system for tables in Angular 6

I recently wanted to enhance my Angular code with a custom table filter. After conducting a web search, I stumbled upon this informative blog post: The implementation worked quite effectively and here is the snippet of the pipe code: import { Pipe, PipeT ...

Using PHP to implement Stripe payment integration

Currently, I am working on a website that has been developed using AngularJS for the front-end and Laravel for the back-end. My goal is to integrate Stripe payment into the platform, but I have encountered some challenges when trying to connect an AngularJ ...

You are not able to use *ngIf nested within *ngFor in Angular 2

I am currently working in Angular2 and trying to bind data from a service. The issue I am facing is that when loading the data, I need to filter it by an ID. Here is what I am trying to achieve: <md-radio-button *ngFor="#item of items_list" ...

Jasmine attempting to access a nonexistent property

I created a very basic component: import { Component } from '@angular/core'; @Component({ selector: 'loading', templateUrl: './loading.component.html', styleUrls: ['./loading.component.scss'] }) export ...

Module import in Ionic

I'm encountering an issue with Ionic, Angular, and TypeScript, and I'm feeling a bit lost... I'm trying to call an external function from my file but I keep getting the following error: "Uncaught (in promise): TypeError: undefined is not an ...

Is there a way to incorporate an AlertService (specifically mat snackbar for displaying error messages) within a different service?

I'm facing a challenge where I want to subscribe to an observable within a service. The catch is, I also need to utilize the AlertService to display error messages. Essentially, I have a service within another service, which seems to be causing a circ ...

Issues encountered when trying to implement a Navbar drop-down menu using Angular in conjunction with Bootstrap 4

I'm currently working on a web application using Angular 5 and Bootstrap 4, and I've encountered issues with the navigation menu bar dropdowns. Despite following the guidelines provided in the official documentation here, I can't seem to get ...

Improving the structure of destructured props by including type annotations. TypeScript implementation in React with Redux. Error code TS

When working with the destructured props from the redux state in the mapStateToProps() function, I encountered a nested structure issue. How can I properly apply the HeaderStateMap types to address this? The compiler is generating the following error messa ...

Guide on deploying an Angular 2 CLI project on a locally hosted Ubuntu production server

I'm currently working on setting up a locally hosted Ubuntu server and I'm looking to deploy an Angular 2 CLI project on it. I'm fairly new to Angular 2, so any assistance would be greatly appreciated! ...

The node_module is not synchronizing properly with the host

I am currently attempting to dockerize an Angular application, but I am encountering issues with mapping. FROM node:alpine as builder RUN apk update && apk add --no-cache make git # Create app directory RUN mkdir /app # Project and dependencies ar ...

Accessing TypeScript object in HTML using Angular 2

I'm curious if there is a way to create an isolated scope for an object in my HTML within a component in my Angular 2 application. For instance, imagine I have the following object in my component's TS file: private myObj = { nestedObj1: { ...

The process of upgrading all dependencies to a particular version

I need guidance on upgrading a project from Angular 6 to version 7. The challenge lies in updating numerous dependencies as well. Most tutorials available only cover upgrading to the latest version (v8), rather than a specific one. Can anyone provide ins ...

I am experiencing difficulties with *ngIf in my HTML as it is not functioning properly, however, the ng

I have come across many inquiries related to this issue, but none of them proved helpful for me. Below is my HTML code: <div class="pl-lg-4"> <div *ngIf="isStorySelected; else hi" class="row"> ...

Creating a factory function for a generic class without repeating the signature

Here is an example code snippet: interface ValueGenerator { next(): any; } class NumberGenerator { next(): number { return 1; } } class ArrayMaker<T extends ValueGenerator> { private generator: T; constructor(valueGene ...

Guide on sorting an array within a specific range and extracting a sample on each side of the outcome

I need a simple solution for the following scenario: let rangeOfInterest = [25 , 44]; let input = [10, 20, 30, 40, 50, 60]; I want to extract values that fall between 25 and 44 (inclusive) from the given input. The range may be within or outside the inpu ...

Incorporating responsive design with React and Typescript

Trying to utilize React with TypeScript, I aim to dynamically generate components based on a field name // Storing all available components const components = { ComponentA, ComponentB, }; // Dynamically render the component based on fieldName const di ...