feat(options-provider): allow to listen for changes
This CL adds logic so features/scripts can subscribe to changes to the
options configuration.
Change-Id: I64fbee8a8c6a253fa93b2ffb7a3adf50292c4160
diff --git a/src/common/options/OptionsConfiguration.ts b/src/common/options/OptionsConfiguration.ts
new file mode 100644
index 0000000..78f3692
--- /dev/null
+++ b/src/common/options/OptionsConfiguration.ts
@@ -0,0 +1,32 @@
+import {
+ OptionCodename,
+ OptionsValues,
+ optionCodenames,
+} from './optionsPrototype';
+
+/**
+ * Representation of a specific configuration of the option values.
+ */
+export class OptionsConfiguration {
+ constructor(public optionsValues: OptionsValues) {}
+
+ getOptionValue<O extends OptionCodename>(option: O): OptionsValues[O] {
+ return this.optionsValues[option];
+ }
+
+ isEnabled(option: OptionCodename): boolean {
+ const value = this.getOptionValue(option);
+ return value === true;
+ }
+
+ isEqualTo(otherConfiguration: OptionsConfiguration) {
+ for (const option of optionCodenames) {
+ const thisValue = this.getOptionValue(option);
+ const otherValue = otherConfiguration.getOptionValue(option);
+ if (thisValue !== otherValue) {
+ return false;
+ }
+ }
+ return true;
+ }
+}