store icon indicating copy to clipboard operation
store copied to clipboard

📚[DOCS]: Recipes - Style Guide - Example Code

Open HansMusterWhatElse opened this issue 4 years ago • 2 comments

Description

Hi guys,

First of all - great job with the NGXS-framework and documentation. I really enjoyed reading through it in my free time.

Just recently I came across this part in the Style Guide documentation.

Regarding that example code I have a few questions:

  • Is there a particular reason that it's adviced to have tiny injectable sub states instead of something like an aggregate root which manages all substates for that particular concern?

  • Is there a particular need to have this sub state (e.g GridStateModel) inejctable? Is this needed in order to work with Angular in the first place?

  • Is this considered best-practise for NGXS?

Thanks in advance!

Best Regards Hans

HansMusterWhatElse avatar May 11 '20 06:05 HansMusterWhatElse

@HansMusterWhatElse I am very new to Angular and been using ngxs for a couple of months so I don't have enough experience.

But regarding your question about substates I think it has something to do with how original redux works (combineReducers) where instead of declaring a big, more complicated state slice and reducer, a better approach is to declare small reducers and combine them in the end. it is more manageable. So I think the idea of substates may come from that original redux implementation.

bboydflo avatar May 13 '20 22:05 bboydflo

I definitely get that but what would be the whole point of making something like the following injectable? Wouldn't that be pointless without the proper context? You can definitely sign me up for small states but for me they should have a reason to be independent.

Thanks anyways for your response! :)

@State<RowStateModel>({
  name: 'row',
  defaults: {
    id: -1
  }
})
@Injectable()
export class RowState {}

HansMusterWhatElse avatar May 14 '20 10:05 HansMusterWhatElse