From 317c5a1ff848fa5dbb4a5563966cf7a5be97476a Mon Sep 17 00:00:00 2001 From: Steffen Date: Thu, 4 Feb 2021 21:55:04 +0100 Subject: [PATCH] reduce custom role transport by replacing object keys with numerical indices --- src/store/index.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 7830629..4703a6d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -105,11 +105,13 @@ export default new Vuex.Store({ getters: { /** * 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 * @returns {[]} */ customRolesStripped: ({ roles }) => { const customRoles = []; + const customKeys = Object.keys(customRole); const strippedProps = [ "firstNightReminder", "otherNightReminder", @@ -125,11 +127,8 @@ export default new Vuex.Store({ continue; } const value = role[prop]; - if ( - Object.keys(customRole).includes(prop) && - value !== customRole[prop] - ) { - strippedRole[prop] = value; + if (customKeys.includes(prop) && value !== customRole[prop]) { + strippedRole[customKeys.indexOf(prop)] = value; } } customRoles.push(strippedRole); @@ -165,6 +164,21 @@ export default new Vuex.Store({ setCustomRoles(state, roles) { state.roles = new Map( 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( role =>