mirror of
https://github.com/nasa/openmct.git
synced 2025-02-15 23:22:58 +00:00
33 lines
902 B
JavaScript
33 lines
902 B
JavaScript
define(['EventEmitter'], function (EventEmitter) {
|
|
function Selection() {
|
|
EventEmitter.call(this);
|
|
this.selectedValues = [];
|
|
}
|
|
|
|
Selection.prototype = Object.create(EventEmitter.prototype);
|
|
|
|
Selection.prototype.select = function (value) {
|
|
this.selectedValues.push(value);
|
|
this.emit('change', this.selectedValues);
|
|
return this.deselect.bind(this, value);
|
|
};
|
|
|
|
Selection.prototype.deselect = function (value) {
|
|
this.selectedValues = this.selectedValues.filter(function (v) {
|
|
return v !== value;
|
|
});
|
|
this.emit('change', this.selectedValues);
|
|
};
|
|
|
|
Selection.prototype.selected = function () {
|
|
return this.selectedValues;
|
|
};
|
|
|
|
Selection.prototype.clear = function () {
|
|
this.selectedValues = [];
|
|
this.emit('change', this.selectedValues);
|
|
};
|
|
|
|
return Selection;
|
|
});
|