0

On the 2nd line, I am getting 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 am trying to refactor "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 am having difficulty in how to refactor based on this hasCreateCasePermission .

1 Answers1

0

Side note: The use of .projector in the first sample is a bit of a smell. You can do the following:

const hasCreateCasePermission = hasPermission({
        resource: PermissionResource.case,
        action: PermissionAction.create,
});
timdeschryver
  • 14,415
  • 1
  • 19
  • 32