in src/service.ts [405:444]
private embedExisting(element: IPowerBiElement, config: IComponentEmbedConfiguration | IEmbedConfigurationBase, phasedRender?: boolean): Embed {
const component = utils.find((x) => x.element === element, this.embeds);
if (!component) {
throw new Error(`Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML} which already has embedded component associated, but could not find the existing component in the list of active components. This could indicate the embeds list is out of sync with the DOM, or the component is referencing the incorrect HTML element.`);
}
// TODO: Multiple embedding to the same iframe is not supported in QnA
if (config.type && config.type.toLowerCase() === "qna") {
return this.embedNew(element, config);
}
/**
* TODO: Dynamic embed type switching could be supported but there is work needed to prepare the service state and DOM cleanup.
* remove all event handlers from the DOM, then reset the element to initial state which removes iframe, and removes from list of embeds
* then we can call the embedNew function which would allow setting the proper embedUrl and construction of object based on the new type.
*/
if (typeof config.type === "string" && config.type !== component.config.type) {
/**
* When loading report after create we want to use existing Iframe to optimize load period
*/
if (config.type === "report" && component.config.type === "create") {
const report = new Report(this, element, config, /* phasedRender */ false, /* isBootstrap */ false, element.powerBiEmbed.iframe);
component.populateConfig(config, /* isBootstrap */ false);
report.load();
element.powerBiEmbed = report;
this.addOrOverwriteEmbed(component, element);
return report;
}
throw new Error(`Embedding on an existing element with a different type than the previous embed object is not supported. Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML}, but the existing element contains an embed of type: ${this.config.type} which does not match the new type: ${config.type}`);
}
component.populateConfig(config, /* isBootstrap */ false);
component.load(phasedRender);
return component;
}