On the second line, I get this error: Selectors with props are deprecated.
const getUserProfileState = createFeatureSelector<UserProfileState>(authorizationFeatureKey); const hasPermission = createSelector( getUserProfileState, (state: UserProfileState, permission: GQLPermission): boolean => { const result = state.permissions && state.permissions.some((p) => p && p.resource === permission.resource && p.action === permission.action); return !!result; } ); const hasCreateCasePermission = createSelector(getUserProfileState, (state: UserProfileState): boolean => hasPermission.projector(state, { resource: PermissionResource.case, action: PermissionAction.create, }) );
I'm trying to refactor the "hasPermission" function like this:
const hasPermission = (permission: GQLPermission) => createSelector( getUserProfileState, (state: UserProfileState): boolean => { const result = state.permissions && state.permissions.some((p) => p && p.resource === permission.resource && p.action === permission.action); return !!result; } );
But I'm having difficulty on how to refactor based on this hasCreateCasePermission.
Side note: The use of
.projector
in the first example is a bit flavorful. You can do the following: