@awayjs/core
Version:
AwayJS core classes
52 lines (51 loc) • 1.63 kB
JavaScript
import { __extends } from "tslib";
import { AssetBase } from './AssetBase';
var USE_WEAK = ('WeakRef' in self);
/**
*
* @export class away.pool.AbstractionBase
*/
var AbstractionBase = /** @class */ (function (_super) {
__extends(AbstractionBase, _super);
function AbstractionBase() {
var _this = _super.call(this) || this;
_this._invalid = true;
return _this;
}
AbstractionBase.prototype.init = function (asset, pool, useWeak) {
if (useWeak === void 0) { useWeak = false; }
this._useWeak = USE_WEAK && useWeak;
this._asset = this._useWeak ? new self.WeakRef(asset) : asset;
this._assetId = asset.id;
this._assetType = asset.assetType;
this._pool = pool;
this._invalid = true;
if (this._useWeak)
this._pool.abstractions.finalizer.register(asset, asset.id, this);
asset.addAbstraction(this);
};
/**
*
*/
AbstractionBase.prototype.onClear = function () {
var _a;
if (this._useWeak) {
this._pool.abstractions.finalizer.unregister(this);
(_a = this._asset.deref()) === null || _a === void 0 ? void 0 : _a.removeAbstraction(this);
}
else {
this._asset.removeAbstraction(this);
}
this._pool.abstractions.clearAbstraction(this._assetId, this._assetType);
this._pool = null;
this._asset = null;
};
/**
*
*/
AbstractionBase.prototype.onInvalidate = function () {
this._invalid = true;
};
return AbstractionBase;
}(AssetBase));
export { AbstractionBase };