UNPKG

ecol

Version:
197 lines 7.21 kB
"use strict"; 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 __()); }; })(); var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var Vector_1 = require("tstl/container/Vector"); var CollectionEvent_1 = require("../basic/CollectionEvent"); var EventDispatcher_1 = require("../basic/EventDispatcher"); var ArrayCollection = /** @class */ (function (_super) { __extends(ArrayCollection, _super); function ArrayCollection() { var _this = _super !== null && _super.apply(this, arguments) || this; /** * @hidden */ _this.dispatcher_ = new EventDispatcher_1.EventDispatcher(); return _this; } /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ // using super.constructor; ArrayCollection.prototype.clear = function () { var first = this.begin(); var last = this.end(); this._Notify_erase(first, last); _super.prototype.clear.call(this); }; /* ========================================================= ELEMENTS I/O - INSERT - ERASE - REFRESH ============================================================ INSERT --------------------------------------------------------- */ /** * @inheritdoc */ ArrayCollection.prototype.push = function () { var items = []; for (var _i = 0; _i < arguments.length; _i++) { items[_i] = arguments[_i]; } var n = this.size(); var ret = _super.prototype.push.apply(this, __spread(items)); this._Notify_insert(this.begin().advance(n), this.end()); return ret; }; /** * @inheritdoc */ ArrayCollection.prototype.push_back = function (val) { _super.prototype.push.call(this, val); this._Notify_insert(this.end().prev(), this.end()); }; /** * @hidden */ ArrayCollection.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, ret.advance(n)); return ret; }; /* --------------------------------------------------------- ERASE --------------------------------------------------------- */ /** * @inheritdoc */ ArrayCollection.prototype.pop_back = function () { this._Notify_erase(this.end().prev(), this.end()); _super.prototype.pop_back.call(this); }; /** * @hidden */ ArrayCollection.prototype._Erase_by_range = function (first, last) { this._Notify_erase(first, last); return _super.prototype._Erase_by_range.call(this, first, last); }; /* --------------------------------------------------------- REFRESH --------------------------------------------------------- */ /** * @inheritDoc */ ArrayCollection.prototype.set = function (index, val) { _super.prototype.set.call(this, index, val); this.refresh(this.begin().advance(index)); }; ArrayCollection.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)); }; /* ========================================================= EVENT DISPATCHER - NOTIFIERS - ACCESSORS ============================================================ NOTIFIERS --------------------------------------------------------- */ /** * @inheritdoc */ ArrayCollection.prototype.dispatchEvent = function (event) { if (this.dispatcher_) this.dispatcher_.dispatchEvent(event); }; /** * @hidden */ ArrayCollection.prototype._Notify_insert = function (first, last) { this.dispatchEvent(new CollectionEvent_1.CollectionEvent("insert", first, last)); }; /** * @hidden */ ArrayCollection.prototype._Notify_erase = function (first, last) { this.dispatchEvent(new CollectionEvent_1.CollectionEvent("erase", first, last)); }; /* --------------------------------------------------------- ACCESSORS --------------------------------------------------------- */ /** * @inheritdoc */ ArrayCollection.prototype.hasEventListener = function (type) { return this.dispatcher_.hasEventListener(type); }; /** * @inheritdoc */ ArrayCollection.prototype.addEventListener = function (type, listener) { this.dispatcher_.addEventListener(type, listener); }; /** * @inheritdoc */ ArrayCollection.prototype.removeEventListener = function (type, listener) { this.dispatcher_.removeEventListener(type, listener); }; return ArrayCollection; }(Vector_1.Vector)); exports.ArrayCollection = ArrayCollection; (function (ArrayCollection) { ArrayCollection.Event = CollectionEvent_1.CollectionEvent; ArrayCollection.Iterator = Vector_1.Vector.Iterator; ArrayCollection.ReverseIterator = Vector_1.Vector.ReverseIterator; })(ArrayCollection = exports.ArrayCollection || (exports.ArrayCollection = {})); exports.ArrayCollection = ArrayCollection; var old_swap = Vector_1.Vector.prototype.swap; Vector_1.Vector.prototype.swap = function (obj) { old_swap.call(this, obj); if (this instanceof ArrayCollection) this.refresh(); if (obj instanceof ArrayCollection) obj.refresh(); }; //# sourceMappingURL=ArrayCollection.js.map