已弃用:不再支持带有 props 的选择器
P粉786800174
P粉786800174 2024-02-21 20:05:20
0
1
424

在第二行,我收到此错误:不推荐使用带有 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 进行重构方面遇到了困难。

P粉786800174
P粉786800174

全部回复(1)
P粉465287592

旁注:第一个示例中使用 .projector 有点味道。 您可以执行以下操作:

const hasCreateCasePermission = hasPermission({
        resource: PermissionResource.case,
        action: PermissionAction.create,
});
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板