Skip to content

Commit 58c7b5b

Browse files
committed
Consistently dispatch events, if needed, when setting AppOptions
Currently we'll only dispatch events, for the options that support it, when updating preferences. Since this could potentially lead to inconsistent behaviour, let's avoid any future surprises by *always* dispatching events regardless of how the relevant option is being changed. Obviously we should then also dispatch events in `AppOptions.set`, and to avoid adding even more duplicated code this method is changed into a wrapper for `AppOptions.setAll`. While this is technically a tiny bit less efficient I don't think it matters in practice, since outside of development- and debug-mode `AppOptions.set` is barely used.
1 parent 2efa3e4 commit 58c7b5b

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

web/app_options.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -571,18 +571,7 @@ class AppOptions {
571571
}
572572

573573
static set(name, value) {
574-
const defaultOpt = defaultOptions[name];
575-
576-
if (
577-
!defaultOpt ||
578-
!(
579-
typeof value === typeof defaultOpt.value ||
580-
Type[(typeof value).toUpperCase()] & defaultOpt.type
581-
)
582-
) {
583-
return;
584-
}
585-
userOptions.set(name, value);
574+
this.setAll({ [name]: value });
586575
}
587576

588577
static setAll(options, prefs = false) {
@@ -601,15 +590,16 @@ class AppOptions {
601590
) {
602591
continue;
603592
}
604-
if (prefs) {
605-
const { kind } = defaultOpt;
593+
const { kind } = defaultOpt;
606594

607-
if (!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
608-
continue;
609-
}
610-
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
611-
(events ||= new Map()).set(name, userOpt);
612-
}
595+
if (
596+
prefs &&
597+
!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)
598+
) {
599+
continue;
600+
}
601+
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
602+
(events ||= new Map()).set(name, userOpt);
613603
}
614604
userOptions.set(name, userOpt);
615605
}

0 commit comments

Comments
 (0)