gnome-shell/js/ui/components/__init__.js
Florian Müllner 3b1330880f cleanup: Use Function.prototype.bind()
When not using arrow notation with anonymous functions, we use Lang.bind()
to bind `this` to named callbacks. However since ES5, this functionality
is already provided by Function.prototype.bind() - in fact, Lang.bind()
itself uses it when no extra arguments are specified. Just use the built-in
function directly where possible, and use arrow notation in the few places
where we pass additional arguments.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/23
2018-02-21 13:55:02 +00:00

66 lines
1.6 KiB
JavaScript

const Lang = imports.lang;
const Main = imports.ui.main;
var ComponentManager = new Lang.Class({
Name: 'ComponentManager',
_init() {
this._allComponents = {};
this._enabledComponents = [];
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
this._sessionUpdated();
},
_sessionUpdated() {
let newEnabledComponents = Main.sessionMode.components;
newEnabledComponents.filter(
name => this._enabledComponents.indexOf(name) == -1
).forEach(name => {
this._enableComponent(name);
});
this._enabledComponents.filter(
name => newEnabledComponents.indexOf(name) == -1
).forEach(name => {
this._disableComponent(name);
});
this._enabledComponents = newEnabledComponents;
},
_importComponent(name) {
let module = imports.ui.components[name];
return module.Component;
},
_ensureComponent(name) {
let component = this._allComponents[name];
if (component)
return component;
if (Main.sessionMode.isLocked)
return null;
let constructor = this._importComponent(name);
component = new constructor();
this._allComponents[name] = component;
return component;
},
_enableComponent(name) {
let component = this._ensureComponent(name);
if (component)
component.enable();
},
_disableComponent(name) {
let component = this._allComponents[name];
if (component == null)
return;
component.disable();
}
});