refactor: wrap Object.prototype.hasOwnProperty.call (#25834)
This commit is contained in:
parent
b8f414f4da
commit
83bb065b4f
1 changed files with 9 additions and 5 deletions
|
@ -264,8 +264,12 @@ export const roleList: Record<RoleId, Role> = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasRole = (role: keyof typeof roleList) => {
|
||||||
|
return Object.prototype.hasOwnProperty.call(roleList, role);
|
||||||
|
};
|
||||||
|
|
||||||
const canExecuteRole = (role: keyof typeof roleList) => {
|
const canExecuteRole = (role: keyof typeof roleList) => {
|
||||||
if (!Object.prototype.hasOwnProperty.call(roleList, role)) return false;
|
if (!hasRole(role)) return false;
|
||||||
if (!isMac) return true;
|
if (!isMac) return true;
|
||||||
|
|
||||||
// macOS handles all roles natively except for a few
|
// macOS handles all roles natively except for a few
|
||||||
|
@ -273,20 +277,20 @@ const canExecuteRole = (role: keyof typeof roleList) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getDefaultLabel (role: RoleId) {
|
export function getDefaultLabel (role: RoleId) {
|
||||||
return Object.prototype.hasOwnProperty.call(roleList, role) ? roleList[role].label : '';
|
return hasRole(role) ? roleList[role].label : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultAccelerator (role: RoleId) {
|
export function getDefaultAccelerator (role: RoleId) {
|
||||||
if (Object.prototype.hasOwnProperty.call(roleList, role)) return roleList[role].accelerator;
|
if (hasRole(role)) return roleList[role].accelerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldRegisterAccelerator (role: RoleId) {
|
export function shouldRegisterAccelerator (role: RoleId) {
|
||||||
const hasRoleRegister = Object.prototype.hasOwnProperty.call(roleList, role) && roleList[role].registerAccelerator !== undefined;
|
const hasRoleRegister = hasRole(role) && roleList[role].registerAccelerator !== undefined;
|
||||||
return hasRoleRegister ? roleList[role].registerAccelerator : true;
|
return hasRoleRegister ? roleList[role].registerAccelerator : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultSubmenu (role: RoleId) {
|
export function getDefaultSubmenu (role: RoleId) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(roleList, role)) return;
|
if (!hasRole(role)) return;
|
||||||
|
|
||||||
let { submenu } = roleList[role];
|
let { submenu } = roleList[role];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue