在第二行,我收到此錯誤:不建議使用帶有 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
有點味道。 您可以執行以下操作: