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