Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular): rename default ngrx-selector names to match ngrx-standard #13475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,29 @@ describe('SuperUsers Selectors', () => {
});

describe('SuperUsers Selectors', () => {
it('getAllSuperUsers() should return the list of SuperUsers', () => {
const results = SuperUsersSelectors.getAllSuperUsers(state);
it('selectAllSuperUsers() should return the list of SuperUsers', () => {
const results = SuperUsersSelectors.selectAllSuperUsers(state);
const selId = getSuperUsersId(results[1]);

expect(results.length).toBe(3);
expect(selId).toBe('PRODUCT-BBB');
});

it('getSelected() should return the selected Entity', () => {
const result = SuperUsersSelectors.getSelected(state) as SuperUsersEntity;
it('selectEntity() should return the selected Entity', () => {
const result = SuperUsersSelectors.selectEntity(state) as SuperUsersEntity;
const selId = getSuperUsersId(result);

expect(selId).toBe('PRODUCT-BBB');
});

it('getSuperUsersLoaded() should return the current \\"loaded\\" status', () => {
const result = SuperUsersSelectors.getSuperUsersLoaded(state);
it('selectSuperUsersLoaded() should return the current \\"loaded\\" status', () => {
const result = SuperUsersSelectors.selectSuperUsersLoaded(state);

expect(result).toBe(true);
});

it('getSuperUsersError() should return the current \\"error\\" state', () => {
const result = SuperUsersSelectors.getSuperUsersError(state);
it('selectSuperUsersError() should return the current \\"error\\" state', () => {
const result = SuperUsersSelectors.selectSuperUsersError(state);

expect(result).toBe(ERROR_MSG);
});
Expand Down Expand Up @@ -369,15 +369,15 @@ export class UsersFacade {
private readonly store = inject(Store);

/**
* Combine pieces of state using createSelector,
* Combine pieces of state using createSelector,
* and expose them as observables through the facade.
*/
loaded$ = this.store.pipe(select(UsersSelectors.getUsersLoaded));
allUsers$ = this.store.pipe(select(UsersSelectors.getAllUsers));
selectedUsers$ = this.store.pipe(select(UsersSelectors.getSelected));
loaded$ = this.store.pipe(select(UsersSelectors.selectUsersLoaded));
allUsers$ = this.store.pipe(select(UsersSelectors.selectAllUsers));
selectedUsers$ = this.store.pipe(select(UsersSelectors.selectEntity));

/**
* Use the initialization action to perform one
* Use the initialization action to perform one
* or more tasks in your Effects.
*/
init() {
Expand Down Expand Up @@ -437,38 +437,38 @@ exports[`ngrx should generate the ngrx selectors 1`] = `
import { USERS_FEATURE_KEY, UsersState, usersAdapter } from './users.reducer';

// Lookup the 'Users' feature state managed by NgRx
export const getUsersState = createFeatureSelector<UsersState>(USERS_FEATURE_KEY);
export const selectUsersState = createFeatureSelector<UsersState>(USERS_FEATURE_KEY);

const { selectAll, selectEntities } = usersAdapter.getSelectors();

export const getUsersLoaded = createSelector(
getUsersState,
export const selectUsersLoaded = createSelector(
selectUsersState,
(state: UsersState) => state.loaded
);

export const getUsersError = createSelector(
getUsersState,
export const selectUsersError = createSelector(
selectUsersState,
(state: UsersState) => state.error
);

export const getAllUsers = createSelector(
getUsersState,
export const selectAllUsers = createSelector(
selectUsersState,
(state: UsersState) => selectAll(state)
);

export const getUsersEntities = createSelector(
getUsersState,
export const selectUsersEntities = createSelector(
selectUsersState,
(state: UsersState) => selectEntities(state)
);

export const getSelectedId = createSelector(
getUsersState,
export const selectSelectedId = createSelector(
selectUsersState,
(state: UsersState) => state.selectedId
);

export const getSelected = createSelector(
getUsersEntities,
getSelectedId,
export const selectEntity = createSelector(
selectUsersEntities,
selectSelectedId,
(entities, selectedId) => (selectedId ? entities[selectedId] : undefined)
);
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export class <%= className %>Facade {
private readonly store = inject(Store);

/**
* Combine pieces of state using createSelector,
* Combine pieces of state using createSelector,
* and expose them as observables through the facade.
*/
loaded$ = this.store.pipe(select(<%= className %>Selectors.get<%= className %>Loaded));
all<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.getAll<%= className %>));
selected<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.getSelected));
loaded$ = this.store.pipe(select(<%= className %>Selectors.select<%= className %>Loaded));
all<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectAll<%= className %>));
selected<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectEntity));

/**
* Use the initialization action to perform one
* Use the initialization action to perform one
* or more tasks in your Effects.
*/
init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ describe('<%= className %> Selectors', () => {
});

describe('<%= className %> Selectors', () => {
it('getAll<%= className %>() should return the list of <%= className %>', () => {
const results = <%= className %>Selectors.getAll<%= className %>(state);
it('selectAll<%= className %>() should return the list of <%= className %>', () => {
const results = <%= className %>Selectors.selectAll<%= className %>(state);
const selId = get<%= className %>Id(results[1]);

expect(results.length).toBe(3);
expect(selId).toBe('PRODUCT-BBB');
});

it('getSelected() should return the selected Entity', () => {
const result = <%= className %>Selectors.getSelected(state) as <%= className %>Entity;
it('selectEntity() should return the selected Entity', () => {
const result = <%= className %>Selectors.selectEntity(state) as <%= className %>Entity;
const selId = get<%= className %>Id(result);

expect(selId).toBe('PRODUCT-BBB');
});

it('get<%= className %>Loaded() should return the current "loaded" status', () => {
const result = <%= className %>Selectors.get<%= className %>Loaded(state);
it('select<%= className %>Loaded() should return the current "loaded" status', () => {
const result = <%= className %>Selectors.select<%= className %>Loaded(state);

expect(result).toBe(true);
});

it('get<%= className %>Error() should return the current "error" state', () => {
const result = <%= className %>Selectors.get<%= className %>Error(state);
it('select<%= className %>Error() should return the current "error" state', () => {
const result = <%= className %>Selectors.select<%= className %>Error(state);

expect(result).toBe(ERROR_MSG);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ import { createFeatureSelector, createSelector } from '@ngrx/store';
import { <%= constantName %>_FEATURE_KEY, <%= className %>State, <%= propertyName %>Adapter } from './<%= fileName %>.reducer';

// Lookup the '<%= className %>' feature state managed by NgRx
export const get<%= className %>State = createFeatureSelector<<%= className %>State>(<%= constantName %>_FEATURE_KEY);
export const select<%= className %>State = createFeatureSelector<<%= className %>State>(<%= constantName %>_FEATURE_KEY);

const { selectAll, selectEntities } = <%= propertyName %>Adapter.getSelectors();

export const get<%= className %>Loaded = createSelector(
get<%= className %>State,
export const select<%= className %>Loaded = createSelector(
select<%= className %>State,
(state: <%= className %>State) => state.loaded
);

export const get<%= className %>Error = createSelector(
get<%= className %>State,
export const select<%= className %>Error = createSelector(
select<%= className %>State,
(state: <%= className %>State) => state.error
);

export const getAll<%= className %> = createSelector(
get<%= className %>State,
export const selectAll<%= className %> = createSelector(
select<%= className %>State,
(state: <%= className %>State) => selectAll(state)
);

export const get<%= className %>Entities = createSelector(
get<%= className %>State,
export const select<%= className %>Entities = createSelector(
select<%= className %>State,
(state: <%= className %>State) => selectEntities(state)
);

export const getSelectedId = createSelector(
get<%= className %>State,
export const selectSelectedId = createSelector(
select<%= className %>State,
(state: <%= className %>State) => state.selectedId
);

export const getSelected = createSelector(
get<%= className %>Entities,
getSelectedId,
export const selectEntity = createSelector(
select<%= className %>Entities,
selectSelectedId,
(entities, selectedId) => (selectedId ? entities[selectedId] : undefined)
);