reduce custom role transport by replacing object keys with numerical indices

This commit is contained in:
Steffen 2021-02-04 21:55:04 +01:00
parent a5d6d593c8
commit 317c5a1ff8
1 changed files with 19 additions and 5 deletions

View File

@ -105,11 +105,13 @@ export default new Vuex.Store({
getters: { getters: {
/** /**
* Return all custom roles, with default values and non-essential data stripped. * Return all custom roles, with default values and non-essential data stripped.
* Role object keys will be replaced with a numerical index to conserve bandwidth.
* @param roles * @param roles
* @returns {[]} * @returns {[]}
*/ */
customRolesStripped: ({ roles }) => { customRolesStripped: ({ roles }) => {
const customRoles = []; const customRoles = [];
const customKeys = Object.keys(customRole);
const strippedProps = [ const strippedProps = [
"firstNightReminder", "firstNightReminder",
"otherNightReminder", "otherNightReminder",
@ -125,11 +127,8 @@ export default new Vuex.Store({
continue; continue;
} }
const value = role[prop]; const value = role[prop];
if ( if (customKeys.includes(prop) && value !== customRole[prop]) {
Object.keys(customRole).includes(prop) && strippedRole[customKeys.indexOf(prop)] = value;
value !== customRole[prop]
) {
strippedRole[prop] = value;
} }
} }
customRoles.push(strippedRole); customRoles.push(strippedRole);
@ -165,6 +164,21 @@ export default new Vuex.Store({
setCustomRoles(state, roles) { setCustomRoles(state, roles) {
state.roles = new Map( state.roles = new Map(
roles roles
// replace numerical role object keys with matching key names
.map(role => {
if (role[0]) {
const customKeys = Object.keys(customRole);
const mappedRole = {};
for (let prop in role) {
if (customKeys[prop]) {
mappedRole[customKeys[prop]] = role[prop];
}
}
return mappedRole;
} else {
return role;
}
})
// map existing roles to base definition or pre-populate custom roles to ensure all properties // map existing roles to base definition or pre-populate custom roles to ensure all properties
.map( .map(
role => role =>