ngrx-styleguide
ngrx-styleguide copied to clipboard
Angular style guide may conflict with regard to capitalization
Here is a snippet from your guide and then a snippet from Angular's guide. Angular seems to "prefer" lowerCamelCase over UPPER_CASE.
ngrx-styleguide:
naming actions (for state)
Note: look at actions for side effects here DO name actions with a unique name and captial letters - VERB + NOUN. DO name actions values with - Prefix + VERB + NOUN. Why?: it's readable. Why?: actions can be filtered and viewed in redux dev tool easily. Why?: uniqueness is for making sure only one reducer handles the action.
const UPDATE_FILTER = '[PlayerSearch] UPDATE_FILTER'; const ADD_RESULTS = '[PlayerSearch] ADD_RESULTS';
https://angular.io/guide/styleguide#constants says:
Consider spelling const variables in lower camel case.
Why? Lower camel case variable names (heroRoutes) are easier to read and understand than the traditional UPPER_SNAKE_CASE names (HERO_ROUTES).
Why? The tradition of naming constants in UPPER_SNAKE_CASE reflects an era before the modern IDEs that quickly reveal the const declaration. TypeScript prevents accidental reassignment.
Do tolerate existing const variables that are spelled in UPPER_SNAKE_CASE.
Why? The tradition of UPPER_SNAKE_CASE remains popular and pervasive, especially in third party modules. It is rarely worth the effort to change them at the risk of breaking existing code and documentation.
app/shared/data.service.ts content_copy export const mockHeroes = ['Sam', 'Jill']; // prefer export const heroesUrl = 'api/heroes'; // prefer export const VILLAINS_URL = 'api/villains'; // tolerate
Also, there is an interesting comment at https://github.com/reactjs/redux/issues/1097 from the creator of Redux:
Please use any style you consider appropriate. There's nothing particularly "right" about the style we use in docs. We always discuss important parts (such as reducer purity). The rest is up to you.
Would you agree, based on this information, that we should use lowerCamelCase for our exported action variables?
hi @marcusreese By the Angular styleguide, "Do tolerate existing const variables that are spelled in UPPER_SNAKE_CASE..." I think it's more readable to distinguish when skimming the code. Also, the ngrx-example app uses the same convention - so i would like to somehow follow this one as well.
should switch to the new createAction with recommendations for action types.