UNPKG

econ

Version:
153 lines 5.2 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var 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 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 std = require("tstl"); var CollectionEvent_1 = require("../basic/CollectionEvent"); var EventDispatcher_1 = require("../basic/EventDispatcher"); var List = /** @class */ (function (_super) { __extends(List, _super); function List() { var _this = _super !== null && _super.apply(this, arguments) || this; /** * @hidden */ _this.dispatcher_ = new EventDispatcher_1.EventDispatcher(); return _this; } /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ // using super.constructor; List.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 */ List.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, std.advance(ret, n)); return ret; }; /** * @hidden */ List.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; }; List.prototype.sort = function (comp) { if (comp === void 0) { comp = std.less; } _super.prototype.sort.call(this, comp); this.refresh(); }; /** * @inheritDoc */ List.prototype.reverse = function () { _super.prototype.reverse.call(this); this.refresh(); }; List.prototype.refresh = function (first, last) { if (first === void 0) { first = null; } if (last === void 0) { last = null; } if (first == null) { first = this.begin(); last = this.end(); } else if (last == null) last = first.next(); this.dispatchEvent(new CollectionEvent_1.CollectionEvent("refresh", first, last)); }; /** * @inheritdoc */ List.prototype.dispatchEvent = function (event) { if (this.dispatcher_) this.dispatcher_.dispatchEvent(event); }; /** * @hidden */ List.prototype._Notify_insert = function (first, last) { this.dispatchEvent(new CollectionEvent_1.CollectionEvent("insert", first, last)); }; /** * @hidden */ List.prototype._Notify_erase = function (first, last) { this.dispatchEvent(new CollectionEvent_1.CollectionEvent("erase", first, last)); }; /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ /** * @inheritdoc */ List.prototype.hasEventListener = function (type) { return this.dispatcher_.hasEventListener(type); }; /** * @inheritdoc */ List.prototype.addEventListener = function (type, listener) { this.dispatcher_.addEventListener(type, listener); }; /** * @inheritdoc */ List.prototype.removeEventListener = function (type, listener) { this.dispatcher_.removeEventListener(type, listener); }; return List; }(std.List)); exports.List = List; (function (List) { List.Event = CollectionEvent_1.CollectionEvent; List.Iterator = std.List.Iterator; List.ReverseIterator = std.List.ReverseIterator; })(List = exports.List || (exports.List = {})); exports.List = List; Object.defineProperty(std.List.Iterator.prototype, "value", { get: function () { return this.value_; }, set: function (val) { this.value_ = val; if (this.source() instanceof List) this.source().refresh(this); }, enumerable: true, configurable: true }); var old_swap = std.List.prototype.swap; std.List.prototype.swap = function (obj) { old_swap.call(this, obj); if (this instanceof List) this.refresh(); if (obj instanceof List) obj.refresh(); }; //# sourceMappingURL=List.js.map