Using toSignal and toObservable for RxJS interop

Поділитися
Вставка
  • Опубліковано 7 вер 2024

КОМЕНТАРІ • 48

  • @davidjustice2323
    @davidjustice2323 Рік тому +3

    Thanks Deborah for the hard work to deliver the info for us. I appreciate that 😍

  • @erfanfarhadi
    @erfanfarhadi 9 місяців тому +1

    Thank you for generously sharing your vast knowledge 🙏.
    It is completely clear that true information matters to you 💯.

    • @deborah_kurata
      @deborah_kurata  9 місяців тому +1

      Thank you for watching. And I try. :-)
      I wish there was a way to update content posted to YT as the technology (or best practices) change
      . But no. The best we can do is publish a new video covering the changes.

  • @chagamajaykumarreddy1897
    @chagamajaykumarreddy1897 Рік тому

    Hi Deborah, thank you so much for covering the error handling. looking forward to more awesom videos in latest angular tips and tricks to solve complex problems. thank you so much for awesom video.

    • @deborah_kurata
      @deborah_kurata  Рік тому

      Some of the other error handling features are cool as well. Hoping to get that video pulled together soon.
      Thank you! 🙏

  • @presDev
    @presDev Рік тому

    usefull as always! thanks Deborah!

  • @juanfalcon9507
    @juanfalcon9507 Рік тому

    Thanks Deborah for the job!

  • @sarathlalsaseendran
    @sarathlalsaseendran Рік тому

    Wonderful video as usual

  • @g-luu
    @g-luu Рік тому

    Nice and simple explanation. Just hope they could find another way of handling errors cause try catch gives me nightmares

    • @deborah_kurata
      @deborah_kurata  Рік тому +1

      Thanks!
      They do ... but it takes a bit more to explain fully. I'm planning on doing another video just on error handling in the near future.

  • @estuardohernandez4230
    @estuardohernandez4230 Рік тому

    As usual, your videos are so helpful.

  • @souhaibkhadraoui9898
    @souhaibkhadraoui9898 Рік тому +1

    Thanks again for the great content, I am really enjoying these short videos packed with hands-on knowledge !!
    Usually when learning JS some of us are taught that setting a value to undefined is a "bad practice". Why is undefined allowed here for Signals ? (PS I have now seen multiple videos that set the signal values to undefined and was wondering)

    • @deborah_kurata
      @deborah_kurata  Рік тому +2

      Great to hear that you are enjoying the videos!
      From the MDN docs: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
      "A variable that has not been assigned a value is of type undefined. A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned."
      It's the last sentence there that makes sense in this case. Until the Observable emits, the signal has no value. So it makes sense that it reads as "undefined".
      Also, *our* code doesn't set the value to undefined. The signal default is set to undefined (just like a declaring a variable with no assigned value).
      var x; // x is undefined
      vehicles = toSignal(this.vehicles$); // before the observable emits, vehicles is undefined
      Was that helpful?

    • @souhaibkhadraoui9898
      @souhaibkhadraoui9898 Рік тому +1

      @@deborah_kurata Yes, it makes sense now that you put it in context with Signals !! (as you explained we are not setting a value, simply letting future readers of that signal know that it has no value yet) Thanks !!

  • @soromiso
    @soromiso Рік тому

    Thanks, it helps me to understand how to use signal, it looks like React useEffect look usage. 😮

  • @vamshikunuguntla7626
    @vamshikunuguntla7626 Рік тому

    Great explanation!!

  • @praku78
    @praku78 3 місяці тому

    Hi Deborah, Thanks for the excellent video 🙂. I have doubt, can we use signal inside route gaurd? I tried to use a signal variable eg: this.showUserAccess.set(true); inside canActivate() and trying to use it in another component and its not getting updated, I am using Angular 18.0, let me know whether its right way to use it.

  • @davoodsoleimani9482
    @davoodsoleimani9482 7 місяців тому

    Hey! Thank you. But In the case of using try-catch, is it not possible to handle the errors in the catchError? I think that we can return an empty array instead of error object in the catchError and so no need to use try-catch!

  • @respostasimples
    @respostasimples Рік тому

    you are awesome! thanks for the explanation!

    • @deborah_kurata
      @deborah_kurata  Рік тому +1

      You are most welcome! Thank you for the kind words! 🙏

  • @syedakbar5099
    @syedakbar5099 Рік тому

    Wish there's a video about how signal impacts NgRx

    • @deborah_kurata
      @deborah_kurata  Рік тому +1

      The NgRx team has been working on articles and videos:
      dev.to/ngrx/announcing-ngrx-v16-integration-with-angular-signals-functional-effects-standalone-schematics-and-more-5gk6
      ua-cam.com/video/MsbPkJYrv68/v-deo.html&pp=ygUMbmdyeCBzaWduYWxz
      And I'll add it to my list of possible future topics. Thanks for the suggestion!

  • @ayoubelhayat9650
    @ayoubelhayat9650 Рік тому

    Awesome 🙌🏻

  • @afshin7104
    @afshin7104 9 місяців тому

    Hi Deborah
    Thanks for the clear explanation of the signal
    but what if you wanted to have a vehicle-add components to add vehicle to the signal or even edit the vehicle?

    • @deborah_kurata
      @deborah_kurata  9 місяців тому

      Glad to hear it was useful.
      To define an updatable signal that was originally created with an observable, you can do something like this:
      userTasks = signal([]);
      private userTasks$ = this.http.get(this.todoUrl + 1).pipe(
      tap(tasks => this.userTasks.set(tasks))
      );
      Create a writable signal, then in the pipeline of the Observable, set the data from the Observable to the writable signal. The downside of this approach is that something needs to subscribe (and unsubscribe) to userTasks$.
      I'm still hoping for an easier way to create an updatable signal from an observable as more signal features are added to Angular.

    • @afshin7104
      @afshin7104 9 місяців тому

      @@deborah_kurata so if I am suppose to manually subscribe and unsubscribe then what's the point of creating additional signal inside the service we can achieve the same functionality with subject or behaver subject
      and in real world every data come's from some sort of http request and we list them in some sort of grid , and we edit line without going back to server to request the whole data
      I am getting confused

    • @deborah_kurata
      @deborah_kurata  9 місяців тому +1

      The ultimate goal with signals is to get much better change detection in the user interface to improve performance.
      Using your example, currently if you have a grid of data and update one of the rows, the entire grid is seen as changed and redisplayed.
      With signals, the goal is to have much more fine grained change detection such that modifying a single row will only re-render that row.
      But a few things:
      1) Signals are not yet finished.
      2) As you've found, there is no easy way to modify a signal if the data comes from an HTTP request. (Hopefully this will become easier.)
      3) The UI benefits are not yet fully in place.
      4) Signals don't yet support input properties.
      5) Signals don't yet support two way binding
      So, currently, there are still benefits to start moving toward signals for managing state: the reactivity of computed properties and improved changed detection (currently using OnPush). We'll see more benefits as more signal features are implemented.

    • @afshin7104
      @afshin7104 9 місяців тому +1

      @@deborah_kurata Thank you Deborah for your detailed clarification on this matter
      hopefully other viewers see our discutients and become clear about benefits and limitations
      I wish you could create a video to show getting product-list from http select the product go to edit page update product click back and go to the list without fetching the data from http

  • @MrMagrok
    @MrMagrok 4 місяці тому

    Hi Deborah, fantastic tutorial! I tried to implement toSignal in my application, but I´ve got errors with my Interceptor. I intercept every outgoing request and attach from my ngXS store some User Data. Non-Signal requests are working fine, but when I try to use ToSignal, the value from the store cant be attached. Do you have any idea why?

    • @deborah_kurata
      @deborah_kurata  4 місяці тому

      Thank you for the kind words about the video.
      I've not worked with ngXS, so I don't know enough to answer your question. Consider reaching out to the makers of ngXS and see if they can help you.

    • @MrMagrok
      @MrMagrok 4 місяці тому +1

      @@deborah_kurata Thank you for your answer, deborah! It means a lot :) I got a workaorund and got my values from local Storage and now my Interceptor works just fine. Now I am trying to fix the rest of my code. It just looks so easy in your example, but I struggle sometimes. Maybe I need to step back for a moment and clear my mind.

    • @deborah_kurata
      @deborah_kurata  4 місяці тому

      Yes, stepping back often does help. And there are a few "holes" in signals yet at this point, so that can make it challenging.

  • @TheZukkino
    @TheZukkino Рік тому

    I've noticed a strange behaviour on error management. You approach works properly if are not required mutable signals. In case of mutable signals, I've created in the service, as shown in one of your video, the readOnly version and mutable version assigning its value through pipe operation from the remote API call Observable. The unmanagable behaviour appears when I create the local signal in the component. If, in the computed operation, the readOnly signal is assigned to the local component signal, the error is correctly caught, but any change is not detected (cause of readOnly). On the other case, if I assign the mutable signal, the changes are correctly detected but the errors are uncaught. How can I approach to this scenario?

  • @JoaoOrtiz-fj1pj
    @JoaoOrtiz-fj1pj 10 місяців тому

    Hello Deborah i have a question to u, for example i have this signal animalsSignal = toSignal(this.getAnimals(10,0, filters)) and filters are a object with 3 filter props and user can set value of this filters my problam is when user set filters diferent my signal will be update? or how can i do this update?

    • @deborah_kurata
      @deborah_kurata  9 місяців тому

      I assume getAnimals is an HTTP request? If so, it is one and done. It will only update the signal one time, when the data is first retrieved. It won't emit again, so the signal won't change again.

    • @deborah_kurata
      @deborah_kurata  9 місяців тому

      If you could put together a SMALL stackblitz example with your scenario (NOT your entire application), I would be happy to take a look and propose a solution for you.

    • @JoaoOrtiz-fj1pj
      @JoaoOrtiz-fj1pj 9 місяців тому +1

      @@deborah_kurata yoo deborah all good you solved my question, have a good day :)

  • @NishvanthD
    @NishvanthD 5 днів тому

    while using toObservable should i use takeUnitlDestroy or it it will automatically unsubscribe ??

    • @deborah_kurata
      @deborah_kurata  3 дні тому

      My understanding is that toObservable must be defined within an injection context. I assumed it would then complete the Observable when that context is destroyed.
      But I was not able to find any documentation to back up this understanding. Nor have I experimented with it.
      So, bottom line, I don't know for certain the answer to your question. 😊

    • @NishvanthD
      @NishvanthD 3 дні тому +1

      @@deborah_kurata Thanks for the reply