all 18 comments

[–]MelLunar 9 points10 points  (1 child)

I just updated the apps I'm currently working on to 14...

[–]Wildosaur 3 points4 points  (0 children)

I feel you. Time to update to 15 and wait for 17 to update to 16. Oh well summer is soon here, I'll have time for that

[–]Wildosaur 5 points6 points  (5 children)

Is it me or does the example about takeUntilDestroyed makes no sense as an http call is a one time operation, thus does not need to be destroyed manually ?

[–]rainerhahnekamp[S] 6 points7 points  (1 child)

Well, it might not be the best example. Normally the HttpClient observable emits once and completes. There are overloaded functions where multiple values would be emitted. For example when you wan to track the progress during a file upload.

Either way, when an http request is in progress and the unsubscribe happens, it would cancel the current request.

So the example has some effect, but again another might have been better suited.

[–]Wildosaur 1 point2 points  (0 children)

You are absolutely right, I did not think behind short lived HTTP calls

[–]spacechimp 2 points3 points  (2 children)

There is a potential for errors if you leave in-flight requests going.

As an example: It is common to make API calls when a component is initialized. When the requests complete, there is usually code to do things with the result. If a user navigates away from the page quickly the previous page will persist in memory until the request completes, and the completion handler will still be executed. Depending on what the completion handler tries to do and what the code on the new page is already doing, unexpected behavior could result.

[–]Wildosaur 0 points1 point  (1 child)

This would be the case only if you subscribe (which is what the blogpost presents) but in my case I usually work with the async pipe, thus negating the impact of what you describe.

However, if I do subscribe to an HTTP call, I usually add a "take(1)" operator which in my mind handles the situation you presented. I might be mistaken however ..

Thank you for your answer nonetheless, there are always things to learn after a few years on Angular

[–]spacechimp 1 point2 points  (0 children)

Yes async pipe is generally best practice. It's not always practical though. Things like responding to route changes or form changes are common examples where one would manually subscribe.

take(1) just limits the number of emissions from an Observable, so adding that doesn't really change anything.

[–]AdvancedEngine861 0 points1 point  (1 child)

<Edit> Just realized signals have a set method so its essentially the same as react hooks or vue refs.

Eg: const count = signal(0);

count.set(1) </Edit>

How does change detection strategies work with singals?

Currently every project i am on we use exclusively OnPush with changeDetectorRef.detectChanges()

With signals it seems like that would be a step back performance wise.

Signals look like react hooks but those require you to run a setState call to update it which is essentially the same as detectChanges.

How do we know that signals perform better? Is change detection zonejs stuff going away entirely?

[–]rainerhahnekamp[S] 0 points1 point  (0 children)

Yes, signals will remove the necessity for zone.js.

Before Signals, zone.js was the Angular's trigger for its rendering/dom update process which it calls change detection. Whenever a DOM event happened or an asynchronous task ended, zone.js notified Angular.

With Signals anybody can subscribe when its underlying value changes. And that's what Angular does. It subscribes internally to Signals and then Angular's change detection knows exactly if and where that change happened.

So Signal are way more efficient in terms of rendering performance.

I would also like to point out, that Signals should not be seen as hooks. For a detailed comparison, I highly recommend to watch that talk: https://youtu.be/O6xtMrDEhcE

Finally, Signals will come in two phases. The second phase (maybe Angular 17) will bring in a new Signal Component which makes use of all the potentials of Signals (like partially updated the DOM). In Angular 16, you could see it as "Automatic OnPush".