@pilotlab/lux-tools
Version:
A luxurious user experience framework, developed by your friends at Pilot.
62 lines • 2.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_1 = require("@pilotlab/is");
const debug_1 = require("@pilotlab/debug");
class ActivatableCollection {
constructor(target, isActivateOnAdd = true) {
this.p_collectionName = 'activatable';
this.p_map = new Map();
this.p_isActivateOnAdd = true;
if (is_1.is.notEmpty(target))
this.p_target = target;
this.p_isActivateOnAdd = isActivateOnAdd;
}
get target() { return this.p_target; }
set target(value) { this.p_target = value; }
get isActivateOnAdd() { return this.p_isActivateOnAdd; }
set isActivateOnAdd(value) { this.p_isActivateOnAdd = value; }
add(value) {
if (this.p_map.has(value.name))
return;
if (this.p_isActivateOnAdd)
value.activate(this.p_target);
this.p_map.set(value.name, value);
}
get(name) { return this.p_map.get(name); }
remove(name) {
let value = this.p_map.get(name);
if (is_1.is.notEmpty(value))
value.deactivate();
this.p_map.delete(name);
}
clear() { this.p_map.clear(); }
forEach(callback) {
this.p_map.forEach((value2, key2) => {
return callback(key2, value2);
});
}
activateAll(...args) {
this.p_isActivateOnAdd = true;
this.p_map.forEach((value, key) => {
value.activate(this.p_target, ...args);
return true;
});
}
deactivateAll(...args) {
this.p_isActivateOnAdd = false;
this.p_map.forEach((value, key) => {
value.deactivate(...args);
return true;
});
}
log() {
debug_1.default.log(this.p_collectionName + ':');
this.p_map.forEach((value, key) => {
debug_1.default.log(' ' + key);
return true;
});
}
}
exports.ActivatableCollection = ActivatableCollection;
exports.default = ActivatableCollection;
//# sourceMappingURL=activatableCollection.js.map