ng-messages2
Version:
Angular version of ng-message
145 lines • 5.3 kB
JavaScript
;
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 portal_errors_1 = require("./portal-errors");
/**
* A `Portal` is something that you want to render somewhere else.
* It can be attach to / detached from a `PortalHost`.
*/
var Portal = (function () {
function Portal() {
}
/** Attach this portal to a host. */
Portal.prototype.attach = function (host) {
if (host == null) {
throw new portal_errors_1.NullPortalHostError();
}
if (host.hasAttached()) {
throw new portal_errors_1.PortalAlreadyAttachedError();
}
this._attachedHost = host;
return host.attach(this);
};
/** Detach this portal from its host */
Portal.prototype.detach = function () {
var host = this._attachedHost;
if (host == null) {
throw new portal_errors_1.NoPortalAttachedError();
}
this._attachedHost = null;
return host.detach();
};
Object.defineProperty(Portal.prototype, "isAttached", {
/** Whether this portal is attached to a host. */
get: function () {
return this._attachedHost != null;
},
enumerable: true,
configurable: true
});
/**
* Sets the PortalHost reference without performing `attach()`. This is used directly by
* the PortalHost when it is performing an `attach()` or `detach()`.
*/
Portal.prototype.setAttachedHost = function (host) {
this._attachedHost = host;
};
return Portal;
}());
exports.Portal = Portal;
/**
* A `TemplatePortal` is a portal that represents some embedded template (TemplateRef).
*/
var TemplatePortal = (function (_super) {
__extends(TemplatePortal, _super);
function TemplatePortal(template, viewContainerRef) {
var _this = _super.call(this) || this;
/**
* Additional locals for the instantiated embedded view.
* These locals can be seen as "exports" for the template, such as how ngFor has
* index / event / odd.
* See https://angular.io/docs/ts/latest/api/core/EmbeddedViewRef-class.html
*/
_this.locals = new Map();
_this.templateRef = template;
_this.viewContainerRef = viewContainerRef;
return _this;
}
Object.defineProperty(TemplatePortal.prototype, "origin", {
get: function () {
return this.templateRef.elementRef;
},
enumerable: true,
configurable: true
});
TemplatePortal.prototype.attach = function (host, locals) {
this.locals = locals == null ? new Map() : locals;
return _super.prototype.attach.call(this, host);
};
TemplatePortal.prototype.detach = function () {
this.locals = new Map();
return _super.prototype.detach.call(this);
};
return TemplatePortal;
}(Portal));
exports.TemplatePortal = TemplatePortal;
/**
* Partial implementation of PortalHost that only deals with attaching either a TemplatePortal.
*/
var BasePortalHost = (function () {
function BasePortalHost() {
/** Whether this host has already been permanently disposed. */
this._isDisposed = false;
}
/** Whether this host has an attached portal. */
BasePortalHost.prototype.hasAttached = function () {
return this._attachedPortal != null;
};
BasePortalHost.prototype.attach = function (portal) {
if (portal == null) {
throw new portal_errors_1.NullPortalError();
}
if (this.hasAttached()) {
throw new portal_errors_1.PortalAlreadyAttachedError();
}
if (this._isDisposed) {
throw new portal_errors_1.PortalHostAlreadyDisposedError();
}
if (portal instanceof TemplatePortal) {
this._attachedPortal = portal;
return this.attachTemplatePortal(portal);
}
throw new portal_errors_1.UnknownPortalTypeError();
};
BasePortalHost.prototype.detach = function () {
if (this._attachedPortal) {
this._attachedPortal.setAttachedHost(null);
}
this._attachedPortal = null;
if (this._disposeFn != null) {
this._disposeFn();
this._disposeFn = null;
}
};
BasePortalHost.prototype.dispose = function () {
if (this.hasAttached()) {
this.detach();
}
this._isDisposed = true;
};
BasePortalHost.prototype.setDisposeFn = function (fn) {
this._disposeFn = fn;
};
return BasePortalHost;
}());
exports.BasePortalHost = BasePortalHost;
//# sourceMappingURL=portal.js.map