@@ZoaibKhan It converts the promise if given to an observable, flattens it, uses DestroyRef, which I have never heard of to unsubscribe on destroy, peaks on the initial value in an untracked scope to avoid recursion, does the computation in an untracked scope, and gives back a computed signal based on the objeservable's next value. Its a little bit confusing because it tries to handle a lot of function signatures in the same function
This is a good demonstration. I am a bit stuck on how to effectively handle errors from derivedFrom or derivedAsync. I used to have CatchError before with rxjs , now how to get the errors out of my API call using these new utilities? Bit confused
One way would be to have a standard request response object with some flags like pending, completed and error and return that as part of the result you're getting. Then you can handle the error at the service level and return the relevant flags. In the component then you just have to listen to those flags and show error or success based on it.
@@ZoaibKhan it was down somewhere on his Twitter feed but it was essentially looks like this section in NG extension derivedAsync "Contextual Observable Example" . I am not able to paste the links here in comments but that section gave me some ideas on how to handle errors however in my opinion there's gotta be a standalone section for error handling.
Just creating a simple function will do the trick in this case. The bookIds current value can be used to send to the function and it will update the results.
Pertinent, useful, and very up to date info on the new way of working with Angular. Thanks.
You're welcome 🤗
Cool video, very informative take. Thanks for sharing!
Glad you found it useful! :)
I'm pretty sure some feature I wrote today would have been easier if I saw this first. I may just refactor it to be more like this video. Good stuff.
Glad to hear you found it useful! There's also the ngrx signals package and it's rxMethod function - that does the same thing in an RxJS way...
This is good stuff. Thanks for sharing 👍👍
My pleasure :)
Please also upload videos in urdu for better understanding thanks a lot.
Or we can wrap the signal sets in an untracked scope I guess. But looking at the source code of derivedAsync, its very very clever.
Oh, I haven't looked at it in detail myself. Can you share some of the clever stuff there? :)
@@ZoaibKhan It converts the promise if given to an observable, flattens it, uses DestroyRef, which I have never heard of to unsubscribe on destroy, peaks on the initial value in an untracked scope to avoid recursion, does the computation in an untracked scope, and gives back a computed signal based on the objeservable's next value. Its a little bit confusing because it tries to handle a lot of function signatures in the same function
@@KostasOreopoulos Wow, that's quite a lot! Respect for the maintainers increased even more :)
This is a good demonstration. I am a bit stuck on how to effectively handle errors from derivedFrom or derivedAsync. I used to have CatchError before with rxjs , now how to get the errors out of my API call using these new utilities? Bit confused
One way would be to have a standard request response object with some flags like pending, completed and error and return that as part of the result you're getting. Then you can handle the error at the service level and return the relevant flags.
In the component then you just have to listen to those flags and show error or success based on it.
@@ZoaibKhan ah! Got it, dug a little deeper into this in the past few hours and found "Eneas" explanation on how this can be done . Thanks
@@rkrao8582 welcome. Do share Enea's link here for others as well. It's a good topic to discuss in a video as well
@@ZoaibKhan it was down somewhere on his Twitter feed but it was essentially looks like this section in NG extension derivedAsync "Contextual Observable Example" . I am not able to paste the links here in comments but that section gave me some ideas on how to handle errors however in my opinion there's gotta be a standalone section for error handling.
How do you do with the derivedAsync being initialy undefined for combining it with other signals in a computed ?
You can handle that in the computed itself. Not completely sure, but there should also be an initial value option in derivedAsync...
why can't we used computed in place of derviedAsync?
Because computeds are meant for sync reactivity, they can't have delays or promises or anything async in them.
what if there is a situation where this.bookId will be same but you have re-fetch data from api ,how to trigger the api
Just creating a simple function will do the trick in this case. The bookIds current value can be used to send to the function and it will update the results.
@@ZoaibKhan so I have api call in two different places and I need to set it to same signal in my case it is a read-only signal from toSignal
Check out the video on explicit effect, you'll need to use a writable signal and update it using an effect in that case.