Full stack reactive CRUD in Angular with Go (or any REST API)

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 พ.ย. 2024

ความคิดเห็น • 64

  • @JoshuaMorony
    @JoshuaMorony  7 หลายเดือนก่อน +4

    Next newsletter goes out tomorrow: mobirony.ck.page/4a331b9076

  • @davidjustice2323
    @davidjustice2323 7 หลายเดือนก่อน +12

    We need more of such real world CRUD examples!

  • @tuvok86
    @tuvok86 7 หลายเดือนก่อน +1

    Yes please extend this series. Especially for authentication! I just love your videos!

  • @bjarnekinkel4122
    @bjarnekinkel4122 7 หลายเดือนก่อน +12

    Look grrat, but I would be interested in an example that shows how you would handle bigger amounds of data, as you mentioned in the video. And it would be interesting seeing how you would hamdle loading, error and mybe even retrys.

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      It's not this particular example but I do have a separate video that uses the same approach and covered errors/retries/pagination in more depth: th-cam.com/video/44_IcGPKQ_M/w-d-xo.html

  • @jeffnikelson5824
    @jeffnikelson5824 7 หลายเดือนก่อน +4

    youre the very best, thank you so much! great video and really helped me to understand the approach even better ❤
    would love to see another one about that topic

  • @julienwickramatunga7338
    @julienwickramatunga7338 6 หลายเดือนก่อน

    Really interesting, we're having some serious brainstormings at work about those kind of problems (state management).
    It's in an old Angular 8 app, but your principles of having sources of data "raining" down the app and of coding in a reactive way can still apply.

  • @koles32
    @koles32 7 หลายเดือนก่อน

    I did something similar on ngrx component store. The whole solution looks like spring boot crud repository. It saved soo much time for me.

  • @rembautimes8808
    @rembautimes8808 6 หลายเดือนก่อน

    Thanks for your tutorials . They are awesome 👏

  • @sisaytadesse4419
    @sisaytadesse4419 7 หลายเดือนก่อน +3

    The trick is knowing the few instances for when to deviate from the reactive/declarative context.

  • @osamaabozahra
    @osamaabozahra 7 หลายเดือนก่อน

    Great video, Thanks a lot
    it would be very nice if you made a video showing the whole flow of data and the process with more details.

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      Any particular parts you want to know more about?

    • @osamaabozahra
      @osamaabozahra 7 หลายเดือนก่อน

      @@JoshuaMorony I was thinking about a full feature, covering all aspects of the front-end CRUD, error handling, loading state, retry if fail, ..etc.
      This would be so great, as it will show us the thinking process and how to implement fully reactive feature.
      Thanks in advance ☺️

  • @TravisSomaroo
    @TravisSomaroo 7 หลายเดือนก่อน

    Great stuff Josh, I'd personally like to see more examples of this but there larger data where it would need to be paginated and how we would handle the state. (Some elegant solutions)

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      It's a slightly different example, but this video covers pagination: th-cam.com/video/44_IcGPKQ_M/w-d-xo.html

  • @joaovgarcia
    @joaovgarcia 7 หลายเดือนก่อน

    Great video, just what i was looking for a few weeks ago!
    I would also like to see how you handle relational data, say for example a table object that relates to columns, rows and cells, how to keep track of everything?
    lets say if you create a table it should also create the first row, cell and column, but you could also create those manually after the table is in place.. how would you do it in an efficient and reactive way?

  • @jovanthournout9707
    @jovanthournout9707 7 หลายเดือนก่อน

    @JoshuaMorony Perhaps it is explained in more detail in one of the other videos, but why are the source modeled as behaviorSubjects and not as signals? Whenever an action like an update or add is pushed / set on the signal, it would be possible to react to it using effects? If you need async reactivity, you can use toObservable and use rxjs to do the http call. The result can be subscribed to by using the toSignal rxjs interop function. Do you see any flaws with this approach?

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +1

      A bit of a nit but they are Subjects not BehaviorSubjects, so specifically for representing events not storing state. RxJS/subjects are a better mechanism for representing events so the flow from RxJS to signals works better. For example if I were to try to represent a source as a signal, and an event happens where the same data might be emitted twice (the source might just happen to have the same data twice or it might just be a void type of source), the signal won't actually be triggered because it needs to be a new value each time. This could be worked around perhaps by wrapping the value in something that will always have a unique value, but it's just not really what signals are intended to be used for.

    • @jovanthournout9707
      @jovanthournout9707 7 หลายเดือนก่อน

      @@JoshuaMorony tnx for the explanation

  • @s3ba87
    @s3ba87 7 หลายเดือนก่อน

    @JoshuaMorony what do you use to draw such diagrams?

  • @timothyalcaide
    @timothyalcaide 7 หลายเดือนก่อน +1

    But with this merge when checklistAdded emit, your have two api call... Maybe is better to take result in the switchmap and avoid duplicate api call for checklistAdded case ?

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      Do you mean because we have one request to perform the action (e.g. adding the checklist) and another to refetch the data after any action occurs, whereas we could use the response from the server instead of refetching? Yes you could do this if you wanted to avoid the request to re-fetch, it makes the code slightly more complex but improves performance (there are more improvements we could make like that too)

  • @ahmedaouiche
    @ahmedaouiche 7 หลายเดือนก่อน

    Great video ❤

  • @ARIAS9306
    @ARIAS9306 7 หลายเดือนก่อน

    Great video!, sorry for the off topic question but which vim theme are you using?

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +1

      tokyodark :)

  • @codeSurvivor
    @codeSurvivor 7 หลายเดือนก่อน

    Hi Josh! Thanks for the video, really nice, I love how well you explain things!
    I've been checking the github repo and haven't seen any loading indicators or similar. I guess that there's no feedback while waiting for the backend and the lists just change once the refetch is done, is that right? How would you manage this so the user gets some feedback about what's happening while allowing to still make changes if loading?

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +1

      For situations where I want to show some kind of loading indicator I will have the initial fetch action (e.g. in this case a fetch begins when add/edit/remove are triggered) update the state signal with something like "status: 'loading'" then when any of those merged streams which represent completion emit (e.g. checklistAdded$) I would update the state signal to "status: 'success'" or "status: 'error'". Then I can use that state as the basis for displaying whatever kind of loading indicators I like. Here's an example of that in another app: github.com/joshuamorony/angularstart-chat/blob/main/src/app/auth/login/data-access/login.service.ts

    • @codeSurvivor
      @codeSurvivor 7 หลายเดือนก่อน

      Thanks Josh!

  • @iHelderScrolls
    @iHelderScrolls 7 หลายเดือนก่อน

    Awesome stuff! Have you or will reflect some changes or fixes you showed in earlier videos to the angularstart course?
    Also ngrxstart one day? :p Would really love to see your full approach and have a nice reference project to check when I'm stuck on my work code :)
    And yes for more backend content!!

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +1

      Yeah I'll be doing a big update to Angular Start to incorporate all the more recent stuff, I was hoping to wait for signal based components/the rest of the signals APIs, but we already have most of the stuff now so I'll likely just do a v18 update after it is released

  • @jovanthournout9707
    @jovanthournout9707 7 หลายเดือนก่อน

    @JoshuaMorony I have a follow up question. When one service needs to react to another service, does the service depend on the signal in the other state or best expose the state as an observable. To make it more concrete: If you have an authentication service that tracks the currently logged in user (or anonymous if not logged in) and you have another service, the ProductService that needs to load data from the backend depending on the currently logged in user. Does the product service use the userSignal or does the Authentication service expose the observable for the current user. Or is it all up to flavor? Tnx

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      I think both are fine - generally speaking I prefer to avoid observable -> signal -> observable and instead the ProductService can just react to the same event/stream that is setting the signal in the AuthService. But, if you decide on an architecture where all that the AuthService exposes publicly is the state signal, I think it's fine to have a new source in your ProductService which uses toSignal.

    • @jovanthournout9707
      @jovanthournout9707 7 หลายเดือนก่อน

      @@JoshuaMorony cool, tnx for the confirmation. Keep up the great work, your work inspires me a lot to try to do my frontend dev better 🙏

  • @Daniel-dj7vc
    @Daniel-dj7vc 7 หลายเดือนก่อน +2

    I like this one, the change to the single subscribe was sexy.
    One thing that is bothering me though...will You ever (maybe as a side video) show how could this be converted to the ngrx signal store?

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +2

      Possibly - I'm not actually using Signal Store myself right now, but I think it will likely become the defacto NgRx approach so is definitely worth covering

    • @jordanking3715
      @jordanking3715 7 หลายเดือนก่อน

      @@JoshuaMorony what are you using? state adapt or your own custom built state management?

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +1

      @@jordanking3715 variations on the approach in the video, which are inspired by state adapt but I'm not actually using state adapt. The approach in the video is my "bare bones" approach, but more typically I will also incorporate connect from ngxtension or signalSlice (also ngxtension)

  • @leomaxaguanta9406
    @leomaxaguanta9406 7 หลายเดือนก่อน +1

    do you have video about signal sore?

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      Not yet but people are asking so I'll probably do one soon

  • @returncode0000
    @returncode0000 7 หลายเดือนก่อน

    just brilliant 👍

  • @deadlyecho
    @deadlyecho 7 หลายเดือนก่อน +1

    Is that just to avoid syncing the data after the rest requests using the subscribers to avoid imperative style ? Why not just check if the request failed or succeeded and then update the our signal based on that, would this not work ? I know you tried making the flow as declarative as possible, but I am just asking if this way would also work

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +1

      Do you mean essentially triggering a request from within the subscribe of each request (could also have the server just respond with the data required after each request) and update the state signal from there? Yes, you could do that but as you hinted at its more imperative. I like the declarative style because we just define the data stream once, and it automatically refetches whenever any of its dependencies emit (plus the other benefits of declarative like it being easier to see how/when the data is fetched)

    • @deadlyecho
      @deadlyecho 7 หลายเดือนก่อน

      @@JoshuaMorony Thanks Joshua, yes that's exactly what I meant.. but as you said declarative style is more flexible but there is always a price that has to be paid 😀 in this case ot could be performance depending on the nature of data and other metrics...
      Keep up the good work 👏 🙌

  • @GenichiroV2
    @GenichiroV2 7 หลายเดือนก่อน

    Great content ! i have a little question (not related to this specific video), is using an angular service as a store instead of using ngrx a viable option ? Or should we always consider using ngrx for managing state in a professionnal web app? Thanks

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +1

      It is certainly viable, I'm not using NgRx here for example. The good thing about a state management library is that it generally comes with opinions on how to go about managing state, so if you are rolling your own you should ideally have some sense of how/why you are managing state

  • @filippobertoncelli1870
    @filippobertoncelli1870 7 หลายเดือนก่อน

    great video! super clear explanation as always! one note, at 0:30, how is "get" call the Create part of CRUD? and why is the "post" call a Read?

    • @bric305
      @bric305 7 หลายเดือนก่อน +1

      It was probably just a mistake

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      @@bric305 yep didn't realise they were out of order

    • @filippobertoncelli1870
      @filippobertoncelli1870 7 หลายเดือนก่อน

      @@JoshuaMorony oooh, that's what I thought, but I've learned so much from your videos I wondered if I missed something 😅

  • @HoangPham-xt3fj
    @HoangPham-xt3fj 7 หลายเดือนก่อน +1

    How can I refetch data when quey params are changed?

    • @NuradinPridon
      @NuradinPridon 7 หลายเดือนก่อน

      Make the data be a computed http request from the ActivatedRoute.queryParams. Every time the params change, the request will be sent again and therefore the computed data will update.

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน +2

      Generally you just start with whatever it is you want to react to and pipe off of that. So you might start with a stream of your query params, and then switchMap to the get request

  • @gonzalocorchon6509
    @gonzalocorchon6509 7 หลายเดือนก่อน

    Your solution is OK from a technical point of view, but I guess using libraries such as ngrx/signal-store lead to a cleaner codebase that can be shared across different developers since everybody is going to be using the same architechture/concepts instead of building each one the way they believe is better.

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      I'm not against Signal Store (I think it's good) but this isn't really an ad-hoc approach, it's essentially the redux pattern with a declarative approach. We have actions that are handled by reducers that update state, and side effects if necessary via signal effects. It's just implemented directly using framework primitives/RxJS.

  • @eptic-c
    @eptic-c 7 หลายเดือนก่อน +1

    After using HTMX and AlpineJS for frontend and taking a brake from angular, seeing this monstrosity makes me question why i ever used angular in the first place, god damn.

    • @moveonvillain1080
      @moveonvillain1080 7 หลายเดือนก่อน

      Bro you got a job ... I really wanna get out of Angular as well

  • @sebastianpaduch2527
    @sebastianpaduch2527 7 หลายเดือนก่อน

    Why to subscribe in a service instead of exposing streams with toSignal?
    Subscribing in service does not convince me, even with untilDestroy because (correct me if I'm wrong) singleton in angular app will never be destroyed

    • @JoshuaMorony
      @JoshuaMorony  7 หลายเดือนก่อน

      I talk more about this in this video: th-cam.com/video/R4Ff2bPiWh4/w-d-xo.html - in short, it provides more flexibility with the signals state management (without having to deal with more complex aspects of RxJS/scan). I do sometimes use toSignal though, but for more complex state I will do this manual subscribe approach (which I would typically hide via using some utility like connect or signalSlice from ngxtension). It doesn't matter if this subscribe is in a singleton service, this subscription is supposed to keep running for the entire life of the app.

  • @ttowe
    @ttowe 7 หลายเดือนก่อน

    more backend