The most important consideration in naming is that the name fully and accurately describes the entity/action the variable/function represents.
Exception: variables that contain boolean
const getEmptyString = ''
const emptyString = ''
const valid = true
const isValid = true
Use uppercase with splitting words by underscore(CONSTANT_CASE) for constant variables and dictionaries
const defaultUserRole = ''
const validationMessages = {}
const DEFAULT_USER_ROLE = ''
const VALIDATION_MESSAGES = {}
Exception: not called computed properties and getters in Vue
const validation = () => {}
const validate = () => {}
const valid = () => true
const isAuthorized = () => true
const checkValidity = () => true
const checkAuthorization = () => true
Use variable naming for computed properties without parameter and function naming for computed properties with parameter
computed: {
checkUserAuthorization() {},
userById(id) {}
}
computed: {
isUserAuthorized() {},
getUserById(id) {}
}
methods: {
isUserAuthorized() {},
user() {}
}
methods: {
checkUserAuthorization() {},
getUser() {}
}
<CustomComponent @event-name="action" />
<CustomComponent @event-name="onAction" />
<CustomComponent @event-name="onEventName" />
mutations: {
createUser() {},
changeSettings() {}
}
mutations: {
ADD_USER() {},
UPDATE_SETTINGS() {}
}
Better use modules for every entity with constant set of consistent mutations
// modules/moduleA
mutations: {
ADD() {},
SET() {},
UPDATE() {},
DELETE() {},
}
// modules/moduleB
mutations: {
ADD() {},
SET() {},
UPDATE() {},
DELETE() {},
}
actions: {
googleAuthorization() {}
}
actions: {
authorizeByGoogle() {}
}
getters: {
getUser() {},
checkUserAuthorization() {},
userById(id) {}
}
getters: {
user() {},
isUserAuthorized() {},
getUserById(id) {}
}