在第二行,我收到此错误:不推荐使用带有 props 的选择器。
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, }) );
我正在尝试重构“hasPermission”函数,如下所示:
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; } );
但是我在如何基于这个 hasCreateCasePermission 进行重构方面遇到了困难。
旁注:第一个示例中使用
.projector
有点味道。 您可以执行以下操作: