@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular
69 lines • 2.63 kB
JavaScript
var InjectionRegistery = /** @class */ (function () {
function InjectionRegistery(injectionService) {
this.injectionService = injectionService;
this.defaults = {};
this.components = new Map();
}
InjectionRegistery.prototype.getByType = function (type) {
if (type === void 0) { type = this.type; }
return this.components.get(type);
};
InjectionRegistery.prototype.create = function (bindings) {
return this.createByType(this.type, bindings);
};
InjectionRegistery.prototype.createByType = function (type, bindings) {
bindings = this.assignDefaults(bindings);
var component = this.injectComponent(type, bindings);
this.register(type, component);
return component;
};
InjectionRegistery.prototype.destroy = function (instance) {
var compsByType = this.components.get(instance.componentType);
if (compsByType) {
var idx = compsByType.indexOf(instance);
if (idx > -1) {
var component = compsByType[idx];
component.destroy();
compsByType.splice(idx, 1);
}
}
};
InjectionRegistery.prototype.destroyAll = function () {
this.destroyByType(this.type);
};
InjectionRegistery.prototype.destroyByType = function (type) {
var comps = this.components.get(type);
if (comps) {
for (var _i = 0, comps_1 = comps; _i < comps_1.length; _i++) {
var comp = comps_1[_i];
this.destroy(comp);
}
}
};
InjectionRegistery.prototype.assignDefaults = function (bindings) {
var _a = this.defaults, inputs = _a.inputs, outputs = _a.outputs;
if (!bindings.inputs && !bindings.outputs) {
bindings = { inputs: bindings };
}
if (inputs) {
bindings.inputs = Object.assign(inputs, bindings.inputs);
}
if (outputs) {
bindings.outputs = Object.assign(outputs, bindings.outputs);
}
return bindings;
};
InjectionRegistery.prototype.injectComponent = function (type, bindings) {
return this.injectionService.appendComponent(type, bindings);
};
InjectionRegistery.prototype.register = function (type, component) {
if (!this.components.has(type)) {
this.components.set(type, []);
}
var types = this.components.get(type);
types.push(component);
};
return InjectionRegistery;
}());
export { InjectionRegistery };
//# sourceMappingURL=injection-registery.service.js.map