There is an old-school strategy you could try. Its centered around bitfields and bitmasks. Its quite flexible and not as computationally heavy as other approaches.
Instead of passing around individual Boolean properties, store state in one numeric variable that represents the on/off states of all of your flags - where each flag is represented by a bit that is a power of 2.
Let's use Javascript's binary number syntax to illustrate what this could look like for 8 flags.
let flags = 0b00000000;
Each flag is represented by one of the 8 digits after the prefix '0b'. And they can be in one of two states ON - represented by 1, or OFF represented by 0 - which you can mentally map to TRUE and FALSE.
Let's assume the flags are assigned from right to left. Flag_1 is represented by the first digit on the far right, Flag_2 is to the left of Flag_1, and so on until we get to the 8th digit from the right that represents Flag_8.
If you set the flags variable as follows:
flags = 0b10010111;
You have effectively 'turned on' flags 8, 5, 3, 2, and 1.
To check if flags 3, 2, and 1 are all collectively enabled, you can use a simple combo of bitwise and equality operators to check:
if ((flags & 0b00000111) === 0b00000111) { /* do stuff */ }
You may also want to check if a set of flags are 'turned off'.
To check if flags 3, 2, and 1 are all collectively disabled, the following would suffice:
if ((flags & 0b00000111) === 0) { /* do stuff */ }
To make the code more readable you can define constants for common conditions you test for, and wrap the enable and disable tests in their own respective functions:
const FLAGS_3_2_1 = 0b00000111;
const flagsEnabled = (condition, flags) => (flags & condition) === condition;
const flagsDisabled = (condition, flags) => (flags & condition) === 0;
if (flagsEnabled(FLAGS_3_2_1, flags)) {/* do stuff */}
if (flagsDisabled(FLAGS_3_2_1, flags)) {/* do stuff */}
If you don't like typing out a bunch of ones and zeros, you have the option of using hexadecimal numbers to define conditions instead.
const FLAGS_3_2_1 = 0x07;
If you're into functional programming you can take this even further:
// Conditions to test for
const FLAGS_3_2_1 = 0x07;
const FLAGS_8_7_4_1 = 0xC9;
const generateFlagsEnabledChecker = condition => flags => (flags & condition) === condition;
const generateFlagsDisabledChecker = condition => flags => (flags & condition) === 0;
const flags321Enabled = generateFlagsEnabledChecker(FLAGS_3_2_1);
const flags321Disabled = generateFlagsDisabledChecker(FLAGS_3_2_1);
const flags8741Enabled = generateFlagsEnabledChecker(FLAGS_8_7_4_1);
const flags8741Disabled = generateFlagsDisabledChecker(FLAGS_8_7_4_1);
let flagsToCheck = 0b11001001;
// returns false; bits 3 & 2 are disabled
console.log('Flags 3, 2, and 1 collectively enabled = %s', flags321Enabled(flagsToCheck));
// returns false; bit 1 is enabled
console.log('Flags 3, 2, and 1 collectively disabled = %s', flags321Disabled(flagsToCheck));
// returns true
console.log('Flags 8, 7, 4, and 1 collectively enabled = %s', flags8741Enabled(flagsToCheck));
// returns false
console.log('Flags 8, 7, 4, and 1 collectively disabled = %s', flags8741Disabled(flagsToCheck));
You can store either the binary or hexadecimal representation as a string in properties service and convert it to a number as needed using parseInt(). Just remember to use the appropriate radix as follows:
let convertedFromHex = parseInt(stringHexValue, 16);
let convertedFromBinary = parseInt(stringBinValue, 2);
[flag1, ..., flagN].every((flag) => flag == "false")?