Тёмный

NgRx Best Practices - Episode 4: Facade Pattern 

Rainer Hahnekamp
Подписаться 5 тыс.
Просмотров 4,8 тыс.
50% 1

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

 

1 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 36   
@SzymonPawlowski-o8q
@SzymonPawlowski-o8q 11 месяцев назад
in my company people are mixing executing actions and selectors together in one facade method. imho it violates CQRS. what's your take on it?
@RainerHahnekamp
@RainerHahnekamp 11 месяцев назад
I'm strictly against putting actions and selectors together. This goes completely against CQRS or NgRx's design. In fact, this is actually one of the reason why the NgRx team is not really happy about facades. They have seen these kind of "misuses" quite often.
@MhmmDonuts
@MhmmDonuts Год назад
Man srsly, your "NgRx Best Practices"-Series is by far the best one devs can find on youtube. Thanks u so much so sharing this kind of sugar!!
@RainerHahnekamp
@RainerHahnekamp Год назад
Great, I'm really happy to hear that.
@theGoldyMan
@theGoldyMan 6 месяцев назад
What if I want to test the facade itself. I'm struggling with overrideSelector , setResult and jest-marbles
@RainerHahnekamp
@RainerHahnekamp 6 месяцев назад
Hi, do you mean you want to mock the complete NgRx and only the class with the facade? Then you would have to use the mocking features for NgRx: ngrx.io/guide/store/testing
@arnoldm5358
@arnoldm5358 3 месяца назад
Hi, great video again! I'm using createActionGroup method to organize actions from the source which uses them. This way, different actions can lead to the same effect like calling the loadCustomer method from a service for example. This is where I'm struggling with the facade pattern... How can I implement the customerFacade? Do I have to implement several methods like fromPageXLoadCustom(), fromPageYLoadCustomer()... in order to dispatch the right action? I mean that I don't want to loose the origin of each action for debugging purposes.
@RainerHahnekamp
@RainerHahnekamp 3 месяца назад
I see, you are the action hygiene. So you have one facade method per action. If you have multiple actions, then you also have multiple methods. As a side note: If you have multiple actions just for debugging purposes, why don't you add {context: string} property to the action's payload. Saves the the same purpose. On the other side, if you have different load actions, stick to what you have.
@arnoldm5358
@arnoldm5358 3 месяца назад
@@RainerHahnekamp Thank you for your reply! So It seems that using createActionGroup method and a facade service is not really appropriate. The source property in createActionGroup method is the interesting property (as well as the organisation of the actions of course) and unfortunately we can't benefit to use it.
@RainerHahnekamp
@RainerHahnekamp 3 месяца назад
@@arnoldm5358 To be sure there is no misunderstanding. With "stick to what you have", I meant a facade with one method per action.
@bjeouisaber2391
@bjeouisaber2391 8 месяцев назад
Thank you for the high quality Angular/Spring content, good stuff. I have though a question, it is not really related to the topic of this video. In the code example that you provided the shared directory, you put services with 'providedIn: root' inside the decorator, is there a reason for that ? Because usually Singleton services lives under core. What do you think ?
@RainerHahnekamp
@RainerHahnekamp 8 месяцев назад
You mean why I use providedIn: root? If I wouldn't do that, then somebody else would have to provide that service. Otherwise I can't inject it. That somebody else might the AppModule, the providers in bootstrapApplication or I provide it locally on the component level, which is something I usually don't want to do. If you provide the service locally, then the services gets destroyed together with the component. You should also try to avoid providing the services via an NgModule (if you still have them) or bootstrapApplication because tree-shaking will not work them. If there's something unclear, please let me know.
@bjeouisaber2391
@bjeouisaber2391 8 месяцев назад
@@RainerHahnekamp According to Angular Style guide, Singleton services that are shared across the application should live in CoreModule. Well, I understand in your example that core is rather just a namespace/package boundary holder and no module there. I completely agree with what you said about the usage of 'providedIn: root' flag, but that was not my question. The question is: Shouldn't we put those services in core instead of shared namespace ?
@RainerHahnekamp
@RainerHahnekamp 8 месяцев назад
​@@bjeouisaber2391Ah, now I understand what you mean. So you can of course have one place where all your main services reside and call that core. It should be a separate module because you want that both the AppComponent/AppModule and the rest of your application can use those services. The larger your application grows, the more you want to divide up your core services into different sub-modules. If you now rename those core sub-modules to "shared" you end up exactly where I am. Does it makes sense or do you see something that differentiates the core from the other shared modules?
@oscarsangularchannel3956
@oscarsangularchannel3956 Год назад
Champion! Thanks Rainer
@RainerHahnekamp
@RainerHahnekamp Год назад
Thanks Oscar!
@aram5642
@aram5642 Год назад
At 7:58 you are importing CustomersEffect using a deep import path (using tsconfig path). Which brings me to the questions (1) is this on purpose or just a result of WebStorm auto-import? Also (2) Do you think breaking the customers domain into ui + data "libraries" would make sense if the data were to be shared with another module (eg. dashboard)?
@RainerHahnekamp
@RainerHahnekamp Год назад
Hi, so the deep import is alright and can only be done like that because both files are part of the same module. If an NgRx feature state is required by other domain as well, you have two options. You move the feature state into shared and make it therefore a "shared feature state" that can be accessed from everywhere. If you want to limit the libraries, for example only domain dashboard is allowed to access the customers feature state, you need to do more. You have to create an API module and setup the dependency rules so that only dashboard can access that customers-api. You can find a working example for that on github.com/softarc-consulting/sheriff/blob/main/test-projects/angular-i/src/app/customers/api/index.ts
@NicolasLeblanc-z7s
@NicolasLeblanc-z7s 7 месяцев назад
Praise !
@RainerHahnekamp
@RainerHahnekamp 7 месяцев назад
Thanks a lot!
@zokizuan
@zokizuan Год назад
@RainerHahnekamp
@RainerHahnekamp Год назад
👍
@babarqb
@babarqb Год назад
You can remove webstrom left margin while in distraction free mode by going to settings>advanced settings> there is a line named Left margin in distraction free mode. Change its value into 0 and apply settings.
@RainerHahnekamp
@RainerHahnekamp Год назад
Thanks for the hint
@sushantrajhans4795
@sushantrajhans4795 Год назад
Really helpful Rainer, keep it up Waiting for more videos on angular architecture patterns Very rare content #helpful #thanks
@RainerHahnekamp
@RainerHahnekamp Год назад
Hey! Thanks for the compliment. Planning to come up with more videos. For Angular, I'm currently planning a Signal video und a generic one about Playwright / Cypress. There will definitely be one about architecture, when I start creating one about the sheriff project.
@NavnathTheMaratha
@NavnathTheMaratha 9 месяцев назад
I like all your videos...thanks for your hard-work.
@RainerHahnekamp
@RainerHahnekamp 9 месяцев назад
Thanks Navnath, much appreciated!
@gurmohitsinghgrover7694
@gurmohitsinghgrover7694 7 месяцев назад
Thankyou! Very nice explanation.
@RainerHahnekamp
@RainerHahnekamp 7 месяцев назад
You are welcome Gurmohit!
@Yadiel458x
@Yadiel458x Год назад
Hey, very insightful video! I have a question, I've previously read that the facade shouldn't have business logic, what do you think of that? I was thinking that if I have a facade for a component, and is not meant to be consumed by any other component, why not having some business logic in it, that way the container component doesn't have to handle too much.
@RainerHahnekamp
@RainerHahnekamp Год назад
Thanks and yes: Try to move the logic into NgRx if you can. In your case, when you say that you have just one logic for one component only, then maybe the NgRx Component Store is what you want. It allows you to provide the State only for the lifetime and exclusively (i.e. provided) for the component. Also check, if you actually need NgRx for your use case. Maybe, everything you need is just a single service.
@Yadiel458x
@Yadiel458x Год назад
​@@RainerHahnekamp In the actual application I'm working on, we use behavior subjects instead of NgRx. There's a particularly large container component that needs to be broken down (but that's a different story), where a lot of the business logic is handled. I've been considering moving much of this business logic into a couple of facades for specific tasks. Following your customer example, I'm thinking about extracting all customer-related business logic into one facade, and all product-related business into another. These facades are meant to be used exclusively by this component.
@RainerHahnekamp
@RainerHahnekamp Год назад
@@Yadiel458x Ok, ok, I see. Yes that makes sense. I wouldn't call it Facade then anymore but that's not that important. The main thing is that you extract your logic into services.
@jean-yvespelletier5505
@jean-yvespelletier5505 8 месяцев назад
Awesome content again. Thanks!
@RainerHahnekamp
@RainerHahnekamp 8 месяцев назад
My pleasure!
Далее
NgRx Best Practices - Episode 1: Cache & LoadStatus
21:51
Angular's Change Detection
27:31
Просмотров 7 тыс.
КВН 2024 Встреча выпускников
2:00:41
Introducing Playwright
48:53
Просмотров 3,2 тыс.
How do I test and mock Standalone Components
12:29
Просмотров 2,9 тыс.
Quantum NgRx Facades | Sam Julien | #AngularConnect
24:29
Dependency Injection, The Best Pattern
13:16
Просмотров 828 тыс.
8 Design Patterns | Prime Reacts
22:10
Просмотров 417 тыс.
NgRx Best Practices - Episode 2: Architecture & Modules
35:17
Reactive Contexts
12:10
Просмотров 2,8 тыс.
КВН 2024 Встреча выпускников
2:00:41