ngxs / store

🚀 NGXS - State Management for Angular
http://ngxs.io
MIT License
3.54k stars 404 forks source link

is it a best practive to dispatch action called InitXXXPage for each ngOnInit component's page ? #1120

Closed chaouiy closed 5 years ago

arturovt commented 5 years ago

@chaouiy Dude, could you please normally describe your question? Currently I'm not able to answer it as I don't understand what's going on in this question.

splincode commented 5 years ago

Please create the correct issue.

chaouiy commented 5 years ago

@arturovt Sorry, I will make it more explicit. Imagin I want to GetArticle, UpdateLastVisited and NotifyAuthor each time a user visits article page. Is it better to have an action called InitArticlePage that is dispatched in ngOnInit that do all logic listed above or it is better to have 3 actions and that all the three are dispatched from ngOnInit ?

arturovt commented 5 years ago

This depends on you, there is no best practice on dispatching 1 or 3 actions :wink:

chaouiy commented 5 years ago

@arturovt the speaker on this video would not agree with you. He is telling that actions should notify about events (init event in our case) and should not decide how state is updated. this video is recomended by your offitial documentation.

arturovt commented 5 years ago

Dude, I don't really understand your question and how this video is related. The right question is half the answer.

chaouiy commented 5 years ago

@arturovt Please watch from 04:47. He say that the best practice is to dispatch only one action per event.

arturovt commented 5 years ago

The NgRx doesn't allow to dispatch multiple actions at once, but this is not related to the NGXS as it allows to dispatch N actions using just one dispatch method.

chaouiy commented 5 years ago

@arturovt If that is true remove the line from documentation that says same rules in video apply for both ngxs and ngrx. because the main idea of video is this : actions are events not commands. Apparently, you say that is not true and that is a matter of choice means that you don't agree the video

On Sat, Jun 8, 2019, 21:13 Artur Androsovych <notifications@github.com wrote:

The NgRx doesn't allow to dispatch multiple actions at once, but this is not related to the NGXS as it allows to dispatch N actions using just one dispatch method.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ngxs/store/issues/1120?email_source=notifications&email_token=AC4IXWM7OT56OD6Y5AWS373PZQAHBA5CNFSM4HVXAZC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXH3UCA#issuecomment-500152840, or mute the thread https://github.com/notifications/unsubscribe-auth/AC4IXWIA2N6DAXSKXZ7R75LPZQAHBANCNFSM4HVXAZCQ .

arturovt commented 5 years ago

Our docs says A great video on the topic is Good Action Hygiene by Mike Ryan It's for NgRx, but the same naming conventions apply to NGXS. How is that related to what you're saying? :confused:

The title of topic was How should you name your actions?

chaouiy commented 5 years ago

@arturovt It is not about naming. It is about design patterns. Video say : actions are events not commands. You say : actions can be both.

arturovt commented 5 years ago

Dude, you're lying.

You said:

If that is true remove the line from documentation that says same rules in video apply for both ngxs and ngrx

Our docs tells about naming convetion, not about best practices or design patterns.

Video say : actions are events not commands. You say : actions can be both.

Where am I saying that?

Tell me more about what's the difference between event and command.

splincode commented 5 years ago

NGXS extending CQRS pattern, it means that actions - is a command, but you can regard actions as events as well...

chaouiy commented 5 years ago

@splincode @arturovt so please don't recommand that video in documentation if ngxs philosophy don't agree with it. It's so misleading

chaouiy commented 5 years ago

@arturovt commands tell how to update state. Events only notify that a given event happened.

arturovt commented 5 years ago

:confused: :confused:

Looks like you don't understand what our docs tells. image

chaouiy commented 5 years ago

@arturovt it is still misleadong since video talk about design patterns not only naming convention. So you agree only with 10% of the video. And please avoid such words "lying". Peace and love

arturovt commented 5 years ago

@splincode

I still don't understand what's being asked, could you comment please?

splincode commented 5 years ago

@arturovt I think he is confused. And he thinks that we refer to NGRX for the definition of the concept of actions.

markwhitfeld commented 5 years ago

@arturovt and @chaouiy please keep the tone friendly here!

The point is that you can take the approach that you feel is right for your application. My personal preference is to represent the actions that have been taken in the application (usually by the user) as actions, but that does not preclude the idea that I would have other actions to represent internal ideas. As a guideline, if there are multiple actions that are dispatched together in many places then I suspect that it represents some higher level concept and would recommend creating an action representing the source event (as long as I can give it a reasonable name) and then dispatch those three actions from within the handler.

We have included things in the docs that will hopefully be helpful and are not meant as being perscriptive. NGXS allows for many approaches, each of which have their merits, and therefore the choice is yours of which way to go.

chaouiy commented 5 years ago

@markwhitfeld Do you mean that when using ngxs we can safely violate what is said in the video except naming conventions. That means : we can reuse actions and we can subtype actions ?

splincode commented 5 years ago

@chaouiy yes