econ
Version:
Event Collections
196 lines • 6.87 kB
JavaScript
"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 __());
};
})();
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 std = require("tstl");
var CollectionEvent_1 = require("../basic/CollectionEvent");
var EventDispatcher_1 = require("../basic/EventDispatcher");
var Vector = /** @class */ (function (_super) {
__extends(Vector, _super);
function Vector() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @hidden
*/
_this.dispatcher_ = new EventDispatcher_1.EventDispatcher();
return _this;
}
/* ---------------------------------------------------------
CONSTRUCTORS
--------------------------------------------------------- */
// using super.constructor;
Vector.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
*/
Vector.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
*/
Vector.prototype.push_back = function (val) {
_super.prototype.push.call(this, val);
this._Notify_insert(this.end().prev(), this.end());
};
/**
* @hidden
*/
Vector.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
*/
Vector.prototype.pop_back = function () {
this._Notify_erase(this.end().prev(), this.end());
_super.prototype.pop_back.call(this);
};
/**
* @hidden
*/
Vector.prototype._Erase_by_range = function (first, last) {
this._Notify_erase(first, last);
return _super.prototype._Erase_by_range.call(this, first, last);
};
/* ---------------------------------------------------------
REFRESH
--------------------------------------------------------- */
/**
* @inheritDoc
*/
Vector.prototype.set = function (index, val) {
_super.prototype.set.call(this, index, val);
this.refresh(this.begin().advance(index));
};
Vector.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));
};
/* =========================================================
EVENT DISPATCHER
- NOTIFIERS
- ACCESSORS
============================================================
NOTIFIERS
--------------------------------------------------------- */
/**
* @inheritdoc
*/
Vector.prototype.dispatchEvent = function (event) {
if (this.dispatcher_)
this.dispatcher_.dispatchEvent(event);
};
/**
* @hidden
*/
Vector.prototype._Notify_insert = function (first, last) {
this.dispatchEvent(new CollectionEvent_1.CollectionEvent("insert", first, last));
};
/**
* @hidden
*/
Vector.prototype._Notify_erase = function (first, last) {
this.dispatchEvent(new CollectionEvent_1.CollectionEvent("erase", first, last));
};
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritdoc
*/
Vector.prototype.hasEventListener = function (type) {
return this.dispatcher_.hasEventListener(type);
};
/**
* @inheritdoc
*/
Vector.prototype.addEventListener = function (type, listener) {
this.dispatcher_.addEventListener(type, listener);
};
/**
* @inheritdoc
*/
Vector.prototype.removeEventListener = function (type, listener) {
this.dispatcher_.removeEventListener(type, listener);
};
return Vector;
}(std.Vector));
exports.Vector = Vector;
(function (Vector) {
Vector.Event = CollectionEvent_1.CollectionEvent;
Vector.Iterator = std.Vector.Iterator;
Vector.ReverseIterator = std.Vector.ReverseIterator;
})(Vector = exports.Vector || (exports.Vector = {}));
exports.Vector = Vector;
var old_swap = std.Vector.prototype.swap;
std.Vector.prototype.swap = function (obj) {
old_swap.call(this, obj);
if (this instanceof Vector)
this.refresh();
if (obj instanceof Vector)
obj.refresh();
};
//# sourceMappingURL=Vector.js.map