The problem with Angular Signals and Async Reactivity

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024

Комментарии • 29

  • @flywheel56
    @flywheel56 4 месяца назад +1

    Pertinent, useful, and very up to date info on the new way of working with Angular. Thanks.

    • @ZoaibKhan
      @ZoaibKhan  4 месяца назад

      You're welcome 🤗

  • @PatricioHondagneuRoig
    @PatricioHondagneuRoig 4 месяца назад

    Cool video, very informative take. Thanks for sharing!

    • @ZoaibKhan
      @ZoaibKhan  4 месяца назад

      Glad you found it useful! :)

  • @MichaelSmallDev
    @MichaelSmallDev 4 месяца назад

    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.

    • @ZoaibKhan
      @ZoaibKhan  4 месяца назад

      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...

  • @elsecoding8691
    @elsecoding8691 3 месяца назад

    This is good stuff. Thanks for sharing 👍👍

  • @WeAreMuslim320
    @WeAreMuslim320 4 месяца назад

    Please also upload videos in urdu for better understanding thanks a lot.

  • @KostasOreopoulos
    @KostasOreopoulos 3 месяца назад

    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.

    • @ZoaibKhan
      @ZoaibKhan  3 месяца назад

      Oh, I haven't looked at it in detail myself. Can you share some of the clever stuff there? :)

    • @KostasOreopoulos
      @KostasOreopoulos 3 месяца назад

      @@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

    • @ZoaibKhan
      @ZoaibKhan  3 месяца назад +1

      @@KostasOreopoulos Wow, that's quite a lot! Respect for the maintainers increased even more :)

  • @rkrao8582
    @rkrao8582 Месяц назад

    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

    • @ZoaibKhan
      @ZoaibKhan  Месяц назад

      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.

    • @rkrao8582
      @rkrao8582 Месяц назад

      @@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

    • @ZoaibKhan
      @ZoaibKhan  Месяц назад

      @@rkrao8582 welcome. Do share Enea's link here for others as well. It's a good topic to discuss in a video as well

    • @rkrao8582
      @rkrao8582 Месяц назад

      @@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.

  • @tolstoievski4926
    @tolstoievski4926 3 дня назад

    How do you do with the derivedAsync being initialy undefined for combining it with other signals in a computed ?

    • @ZoaibKhan
      @ZoaibKhan  3 дня назад

      You can handle that in the computed itself. Not completely sure, but there should also be an initial value option in derivedAsync...

  • @arpitgarg6459
    @arpitgarg6459 4 месяца назад

    why can't we used computed in place of derviedAsync?

    • @ZoaibKhan
      @ZoaibKhan  4 месяца назад +4

      Because computeds are meant for sync reactivity, they can't have delays or promises or anything async in them.

  • @NishvanthD
    @NishvanthD Месяц назад

    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

    • @ZoaibKhan
      @ZoaibKhan  Месяц назад +1

      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.

    • @NishvanthD
      @NishvanthD Месяц назад

      @@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

    • @ZoaibKhan
      @ZoaibKhan  Месяц назад +1

      Check out the video on explicit effect, you'll need to use a writable signal and update it using an effect in that case.