@awayjs/core
Version:
AwayJS core classes
56 lines (55 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;
}
Object.defineProperty(AbstractionBase.prototype, "asset", {
get: function () {
return this._asset;
},
enumerable: false,
configurable: true
});
AbstractionBase.prototype.init = function (asset, pool, useWeak) {
if (useWeak === void 0) { useWeak = false; }
this._asset = asset;
this._useWeak = USE_WEAK && useWeak;
this._pool = this._useWeak ? new self.WeakRef(pool) : pool;
this._invalid = true;
if (this._useWeak) {
this._asset.finalizer.register(pool, pool.id, this);
this._poolId = pool.id;
}
};
/**
*
*/
AbstractionBase.prototype.onClear = function (event) {
if (this._useWeak) {
this._asset.finalizer.unregister(this);
this._asset.clearAbstraction(this._pool.deref() || this._poolId);
}
else {
this._asset.clearAbstraction(this._pool);
}
this._pool = null;
this._asset = null;
};
/**
*
*/
AbstractionBase.prototype.onInvalidate = function (event) {
this._invalid = true;
};
return AbstractionBase;
}(AssetBase));
export { AbstractionBase };