Use Map to store variants

This commit is contained in:
Romain Vigier
2020-02-27 10:02:06 +01:00
parent 18abccfb20
commit b052d85b43
18 changed files with 149 additions and 151 deletions
+7 -9
View File
@@ -77,23 +77,21 @@ var Themer = class {
}
}
set_variant(night) {
if ( night !== undefined && this.variants ) {
this.current = night ? this.variants.night : this.variants.day;
set_variant(variant) {
if ( variant && this.variants ) {
this.current = this.variants.get(variant);
}
}
reset_theme() {
if ( this.variants ) {
this.current = this.variants.original;
log_debug('Theme has been reset to the user\'s original variant.')
}
this.set_variant('original');
log_debug('Theme has been reset to the user\'s original variant.')
}
update_variants() {
if ( this.variants ) {
const new_theme = this.current;
if ( new_theme && new_theme !== this.variants.day && new_theme !== this.variants.night ) {
if ( new_theme && new_theme !== this.variants.get('day') && new_theme !== this.variants.get('night') ) {
this._update_variants();
}
}
@@ -102,7 +100,7 @@ var Themer = class {
_update_variants() {
if ( this.current ) {
this.variants = Variants.guess_from(this.current);
log_debug('Variants updated: ' + JSON.stringify(this.variants));
log_debug('Variants updated: ' + this.variants);
}
}