Тёмный

Don't make my toSignal mistake in Angular 

Joshua Morony
Подписаться 73 тыс.
Просмотров 7 тыс.
50% 1

My Angular course: angularstart.com/
I was trying to use toSignal in Angular with a global error handler service when I ran into some weird behaviour: when a single error occurred, I was getting tons of error messages spammed on the screen.
It turns out that this was due to the way toSignal handles errors from observable streams, that results in an error being thrown every time a signal is read
Get weekly content and tips exclusive to my newsletter: mobirony.ck.page/4a331b9076
Want to build mobile apps with Angular?: ionicstart.com
0:00 Introduction
1:03 The problem
1:38 Errors as values
2:04 rejectErrors
#angular #rxjs #signals
- More tutorials: modernangular.com
- Follow me on Twitter: / joshuamorony

Опубликовано:

 

4 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 25   
@JoshuaMorony
@JoshuaMorony 2 месяца назад
Join the weekly newsletter: mobirony.ck.page/4a331b9076
@moitp2
@moitp2 2 месяца назад
I am not sure to understand why this is not set by default tbh
@StephenMoreira
@StephenMoreira 2 месяца назад
Short and sweet, thanks for the tip.
@andresmauriciofajardoolaya2721
@andresmauriciofajardoolaya2721 2 месяца назад
Thanks for the content Joshua
@DorianDauphin
@DorianDauphin 2 месяца назад
Thanks for the content, Joshua. In a previous video, you stated that we should use Signal for synchronous tasks and RxJS when dealing with asynchronous tasks, but this still isn't very clear to me. It would be nice if you could make a video with simple examples showing when it is more appropriate to use signals over RxJS, or vice versa. Have a good day !
@dinysanchez
@dinysanchez 2 месяца назад
Thanks Joshua!
@user-ui9ri3hf8d
@user-ui9ri3hf8d 2 месяца назад
great video, thanks for the info :D
@g-luu
@g-luu 2 месяца назад
Great one thanks
@trevormontgomery6795
@trevormontgomery6795 2 месяца назад
I think this might be my problem in something I'm working on. I was getting what seems like a recursion error when I make an http call. An error must be occurring and angular things I've got a recursive function
@shreyanshjain9479
@shreyanshjain9479 2 месяца назад
That's really cool trick❤
@ianokay
@ianokay 2 месяца назад
Very useful information from the cutting edge, nice video thanks. Unfortunate that it seems you have to spam every toSignal in your application with that object property if you want centralized error handling.
@JoshuaMorony
@JoshuaMorony 2 месяца назад
I suppose you could also write a little helper utility if you wanted to have it by default everywhere
@PavelKostenko
@PavelKostenko 2 месяца назад
What code editor are you using, is this nvim inside tmux? Please share your setup
@JoshuaMorony
@JoshuaMorony 2 месяца назад
Yes it is - this video is somewhat old but covers most of what I am using: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-P5QPacz2-ao.html I do have a couple other videos I think that talk about various aspects of my workflow/neovim setup
@richardscholten100
@richardscholten100 23 дня назад
Why Is It When Something Happens, It's Always You RxJS? Thanks, exactly the problem i was facing...
@anon5992
@anon5992 2 месяца назад
how can we utilize @error with this approach?
@christianhalaby832
@christianhalaby832 2 месяца назад
do you think not using signals at all is a set back?
@svenson95
@svenson95 2 месяца назад
I don't really understand what you're doing in 1:50, the as const suffixes. What is happening there? it seems like the status property (a string) gets transformed to a variable / constant. I've never seen this before.
@RodrigoSalesSilva
@RodrigoSalesSilva 2 месяца назад
by default if you set a string to any variable the type will be infered as string, but if you use as const the type will be infered as the exact string, like "let a = 'authenticated' as const" the type of "a" will be infered as 'authenticated', otherwise it would be 'string'.
@svenson95
@svenson95 2 месяца назад
@@RodrigoSalesSilva okay interesting, but what is the benefit of having this status property not as type string but the actual value? In the next slide (2:01) we're just checking if the status value is "error", if i'm not wrong. Sorry if this is obvious, i feel kind of stupid right now :D
@JoshuaMorony
@JoshuaMorony 2 месяца назад
​@@svenson95 this stream needs to return status values that match a union type of "initial | authenticating | authenticated | error", if I return just "error" for example it won't let me do that because type "string" is not assignable to that union type. If I use "as const" the specific string "error" does match that type.
@sergiokagiema9658
@sergiokagiema9658 2 месяца назад
Where are the 4 reads that procude 4 triggers ?
@JoshuaMorony
@JoshuaMorony 2 месяца назад
I think in the example the signal value is only actually referenced once, but it will depend on how many times change detection is triggered - so even if you only accessed the signal once in the template, but CD ran 4 times, it would cause 4 reads
@sergiokagiema9658
@sergiokagiema9658 2 месяца назад
I see, I got it! Thanks for clarifying it!
@leolanese
@leolanese 2 месяца назад
...{rejectErrors: true} nice 👍