Ensure that OptionalContentGroup.visible
cannot be modified from the "outside"
Given that Optional Content visibility is only intended/supported to be updated via the `OptionalContentConfig.setVisibility`-method, this patch actually enforces that now. Note that this will be used by the next patch in the series, and will help prevent inconsistent state in the `OptionalContentConfig`-class. *Please note:* This patch also uncovered a pre-existing bug, related to iterating through the visibility groups in the constructor, for the `baseState === "OFF"` case.
This commit is contained in:
parent
2d6ebc5801
commit
f3d76b42b3
@ -13,14 +13,34 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { objectFromMap, warn } from "../shared/util.js";
|
import { objectFromMap, unreachable, warn } from "../shared/util.js";
|
||||||
|
|
||||||
|
const INTERNAL = Symbol("INTERNAL");
|
||||||
|
|
||||||
class OptionalContentGroup {
|
class OptionalContentGroup {
|
||||||
|
#visible = true;
|
||||||
|
|
||||||
constructor(name, intent) {
|
constructor(name, intent) {
|
||||||
this.visible = true;
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.intent = intent;
|
this.intent = intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
get visible() {
|
||||||
|
return this.#visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
_setVisible(internal, visible) {
|
||||||
|
if (internal !== INTERNAL) {
|
||||||
|
unreachable("Internal method `_setVisible` called.");
|
||||||
|
}
|
||||||
|
this.#visible = visible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OptionalContentConfig {
|
class OptionalContentConfig {
|
||||||
@ -46,17 +66,17 @@ class OptionalContentConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.baseState === "OFF") {
|
if (data.baseState === "OFF") {
|
||||||
for (const group of this.#groups) {
|
for (const group of this.#groups.values()) {
|
||||||
group.visible = false;
|
group._setVisible(INTERNAL, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const on of data.on) {
|
for (const on of data.on) {
|
||||||
this.#groups.get(on).visible = true;
|
this.#groups.get(on)._setVisible(INTERNAL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const off of data.off) {
|
for (const off of data.off) {
|
||||||
this.#groups.get(off).visible = false;
|
this.#groups.get(off)._setVisible(INTERNAL, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +194,7 @@ class OptionalContentConfig {
|
|||||||
warn(`Optional content group not found: ${id}`);
|
warn(`Optional content group not found: ${id}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.#groups.get(id).visible = !!visible;
|
this.#groups.get(id)._setVisible(INTERNAL, !!visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrder() {
|
getOrder() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user