ecol
Version:
Event Collections
156 lines • 5.69 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var List_1 = require("tstl/container/List");
var global_1 = require("tstl/iterator/global");
var comparators_1 = require("tstl/functional/comparators");
var CollectionEvent_1 = require("../basic/CollectionEvent");
var EventDispatcher_1 = require("../basic/EventDispatcher");
var ListCollection = /** @class */ (function (_super) {
__extends(ListCollection, _super);
function ListCollection() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @hidden
*/
_this.dispatcher_ = new EventDispatcher_1.EventDispatcher();
return _this;
}
/* ---------------------------------------------------------
CONSTRUCTORS
--------------------------------------------------------- */
// using super.constructor;
ListCollection.prototype.clear = function () {
var first = this.begin();
var last = this.end();
_super.prototype.clear.call(this);
this._Notify_erase(first, last);
};
/* =========================================================
ELEMENTS I/O
- INSERT & ERASE
- ALGORITHMS
============================================================
INSERT & ERASE
--------------------------------------------------------- */
/**
* @hidden
*/
ListCollection.prototype._Insert_by_range = function (pos, first, last) {
var n = this.size();
var ret = _super.prototype._Insert_by_range.call(this, pos, first, last);
n = this.size() - n;
this._Notify_insert(ret, global_1.advance(ret, n));
return ret;
};
/**
* @hidden
*/
ListCollection.prototype._Erase_by_range = function (first, last) {
var ret = _super.prototype._Erase_by_range.call(this, first, last);
this._Notify_erase(first, last);
return ret;
};
ListCollection.prototype.sort = function (comp) {
if (comp === void 0) { comp = comparators_1.less; }
_super.prototype.sort.call(this, comp);
this.refresh();
};
/**
* @inheritDoc
*/
ListCollection.prototype.reverse = function () {
_super.prototype.reverse.call(this);
this.refresh();
};
ListCollection.prototype.refresh = function (first, last) {
if (first === undefined) {
first = this.begin();
last = this.end();
}
else if (last === undefined)
last = first.next();
this.dispatchEvent(new CollectionEvent_1.CollectionEvent("refresh", first, last));
};
/**
* @inheritdoc
*/
ListCollection.prototype.dispatchEvent = function (event) {
if (this.dispatcher_)
this.dispatcher_.dispatchEvent(event);
};
/**
* @hidden
*/
ListCollection.prototype._Notify_insert = function (first, last) {
this.dispatchEvent(new CollectionEvent_1.CollectionEvent("insert", first, last));
};
/**
* @hidden
*/
ListCollection.prototype._Notify_erase = function (first, last) {
this.dispatchEvent(new CollectionEvent_1.CollectionEvent("erase", first, last));
};
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritdoc
*/
ListCollection.prototype.hasEventListener = function (type) {
return this.dispatcher_.hasEventListener(type);
};
/**
* @inheritdoc
*/
ListCollection.prototype.addEventListener = function (type, listener) {
this.dispatcher_.addEventListener(type, listener);
};
/**
* @inheritdoc
*/
ListCollection.prototype.removeEventListener = function (type, listener) {
this.dispatcher_.removeEventListener(type, listener);
};
return ListCollection;
}(List_1.List));
exports.ListCollection = ListCollection;
(function (ListCollection) {
ListCollection.Event = CollectionEvent_1.CollectionEvent;
ListCollection.Iterator = List_1.List.Iterator;
ListCollection.ReverseIterator = List_1.List.ReverseIterator;
})(ListCollection = exports.ListCollection || (exports.ListCollection = {}));
exports.ListCollection = ListCollection;
Object.defineProperty(List_1.List.Iterator.prototype, "value", {
get: function () {
return this.value_;
},
set: function (val) {
this.value_ = val;
if (this.source() instanceof ListCollection)
this.source().refresh(this);
},
enumerable: true,
configurable: true
});
var old_swap = List_1.List.prototype.swap;
List_1.List.prototype.swap = function (obj) {
old_swap.call(this, obj);
if (this instanceof ListCollection)
this.refresh();
if (obj instanceof ListCollection)
obj.refresh();
};
//# sourceMappingURL=ListCollection.js.map