Skip to content

Commit c6e6e96

Browse files
committed
Merge remote-tracking branch 'powerbi/master'
2 parents 16fa827 + 884ae54 commit c6e6e96

File tree

8 files changed

+98
-36
lines changed

8 files changed

+98
-36
lines changed

dist/powerbi-client.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! powerbi-client v2.6.4 | (c) 2016 Microsoft Corporation MIT */
1+
/*! powerbi-client v2.6.5 | (c) 2016 Microsoft Corporation MIT */
22
declare module "util" {
33
/**
44
* Raises a custom event with event data on the specified HTML element.
@@ -147,6 +147,7 @@ declare module "embed" {
147147
static nameAttribute: string;
148148
static typeAttribute: string;
149149
static type: string;
150+
static maxFrontLoadTimes: number;
150151
allowedEvents: any[];
151152
/**
152153
* Gets or sets the event handler registered for this embed component.
@@ -394,6 +395,10 @@ declare module "embed" {
394395
* @returns {string}
395396
*/
396397
static findGroupIdFromEmbedUrl(url: string): string;
398+
/**
399+
* Sends the config for front load calls, after 'ready' message is received from the iframe
400+
*/
401+
private frontLoadSendConfig(config);
397402
}
398403
}
399404
declare module "ifilterable" {
@@ -1283,6 +1288,7 @@ declare module "service" {
12831288
*/
12841289
load(element: HTMLElement, config?: embed.IEmbedConfigurationBase): embed.Embed;
12851290
embedInternal(element: HTMLElement, config?: embed.IEmbedConfigurationBase, phasedRender?: boolean): embed.Embed;
1291+
getNumberOfComponents(): number;
12861292
/**
12871293
* Given a configuration based on a Power BI element, saves the component instance that reference the element for later lookup.
12881294
*

dist/powerbi.js

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-client",
3-
"version": "2.6.4",
3+
"version": "2.6.5",
44
"description": "JavaScript library for embedding Power BI into your apps. Provides service which makes it easy to embed different types of components and an object model which allows easy interaction with these components such as changing pages, applying filters, and responding to data selection.",
55
"main": "dist/powerbi.js",
66
"typings": "dist/powerbi-client.d.ts",

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const config = {
2-
version: '2.6.4',
2+
version: '2.6.5',
33
type: 'js'
44
};
55

src/embed.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export abstract class Embed {
111111
static typeAttribute = 'powerbi-type';
112112
static type: string;
113113

114+
static maxFrontLoadTimes: number = 2;
115+
114116
allowedEvents = [];
115117

116118
/**
@@ -280,11 +282,6 @@ export abstract class Embed {
280282
* @returns {Promise<void>}
281283
*/
282284
load(config: IEmbedConfigurationBase, phasedRender?: boolean): Promise<void> {
283-
const errors = this.validate(config);
284-
if (errors) {
285-
throw errors;
286-
}
287-
288285
const path = phasedRender && config.type === 'report' ? this.phasedLoadPath : this.loadPath;
289286
return this.service.hpm.post<void>(path, config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
290287
.then(response => {
@@ -549,7 +546,17 @@ export abstract class Embed {
549546
}
550547

551548
if (isLoad) {
549+
const errors = this.validate(this.config);
550+
if (errors) {
551+
throw errors;
552+
}
553+
552554
this.iframe.addEventListener('load', () => this.load(this.config, phasedRender), false);
555+
556+
if (this.service.getNumberOfComponents() <= Embed.maxFrontLoadTimes) {
557+
// 'ready' event is fired by the embedded element (not by the iframe)
558+
this.element.addEventListener('ready', () => this.frontLoadSendConfig(this.config), false);
559+
}
553560
} else {
554561
this.iframe.addEventListener('load', () => this.createReport(this.createConfig), false);
555562
}
@@ -574,4 +581,21 @@ export abstract class Embed {
574581

575582
return groupId;
576583
}
584+
585+
/**
586+
* Sends the config for front load calls, after 'ready' message is received from the iframe
587+
*/
588+
private frontLoadSendConfig(config: IEmbedConfigurationBase): Promise<void> {
589+
const errors = this.validate(config);
590+
if (errors) {
591+
throw errors;
592+
}
593+
594+
return this.service.hpm.post<void>("/frontload/config", config, { uid: this.config.uniqueId }, this.iframe.contentWindow).then(response => {
595+
return response.body;
596+
},
597+
response => {
598+
throw response.body;
599+
});
600+
}
577601
}

src/service.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface IService {
6161

6262
/**
6363
* The Power BI Service embed component, which is the entry point to embed all other Power BI components into your application
64-
*
64+
*
6565
* @export
6666
* @class Service
6767
* @implements {IService}
@@ -89,7 +89,7 @@ export class Service implements IService {
8989

9090
/**
9191
* Gets or sets the access token as the global fallback token to use when a local token is not provided for a report or tile.
92-
*
92+
*
9393
* @type {string}
9494
*/
9595
accessToken: string;
@@ -99,6 +99,7 @@ export class Service implements IService {
9999

100100
/** A list of Dashboard, Report and Tile components that have been embedded using this service instance. */
101101
private embeds: embed.Embed[];
102+
102103
/** TODO: Look for way to make hpm private without sacraficing ease of maitenance. This should be private but in embed needs to call methods. */
103104
hpm: hpm.HttpPostMessage;
104105
/** TODO: Look for way to make wpmp private. This is only public to allow stopping the wpmp in tests */
@@ -109,7 +110,7 @@ export class Service implements IService {
109110

110111
/**
111112
* Creates an instance of a Power BI Service.
112-
*
113+
*
113114
* @param {IHpmFactory} hpmFactory The http post message factory used in the postMessage communication layer
114115
* @param {IWpmpFactory} wpmpFactory The window post message factory used in the postMessage communication layer
115116
* @param {IRouterFactory} routerFactory The router factory used in the postMessage communication layer
@@ -234,7 +235,7 @@ export class Service implements IService {
234235

235236
/**
236237
* TODO: Add a description here
237-
*
238+
*
238239
* @param {HTMLElement} [container]
239240
* @param {embed.IEmbedConfiguration} [config=undefined]
240241
* @returns {embed.Embed[]}
@@ -250,7 +251,7 @@ export class Service implements IService {
250251
* Given a configuration based on an HTML element,
251252
* if the component has already been created and attached to the element, reuses the component instance and existing iframe,
252253
* otherwise creates a new component instance.
253-
*
254+
*
254255
* @param {HTMLElement} element
255256
* @param {embed.IEmbedConfigurationBase} [config={}]
256257
* @returns {embed.Embed}
@@ -264,7 +265,7 @@ export class Service implements IService {
264265
* if the component has already been created and attached to the element, reuses the component instance and existing iframe,
265266
* otherwise creates a new component instance.
266267
* This is used for the phased embedding API, once element is loaded successfully, one can call 'render' on it.
267-
*
268+
*
268269
* @param {HTMLElement} element
269270
* @param {embed.IEmbedConfigurationBase} [config={}]
270271
* @returns {embed.Embed}
@@ -287,9 +288,17 @@ export class Service implements IService {
287288
return component;
288289
}
289290

291+
getNumberOfComponents(): number {
292+
if (!this.embeds) {
293+
return 0;
294+
}
295+
296+
return this.embeds.length;
297+
}
298+
290299
/**
291300
* Given a configuration based on a Power BI element, saves the component instance that reference the element for later lookup.
292-
*
301+
*
293302
* @private
294303
* @param {IPowerBiElement} element
295304
* @param {embed.IEmbedConfigurationBase} config
@@ -318,7 +327,7 @@ export class Service implements IService {
318327

319328
/**
320329
* Given an element that already contains an embed component, load with a new configuration.
321-
*
330+
*
322331
* @private
323332
* @param {IPowerBiElement} element
324333
* @param {embed.IEmbedConfigurationBase} config
@@ -376,7 +385,7 @@ export class Service implements IService {
376385

377386
/**
378387
* Returns an instance of the component associated with the element.
379-
*
388+
*
380389
* @param {HTMLElement} element
381390
* @returns {(Report | Tile)}
382391
*/
@@ -392,7 +401,7 @@ export class Service implements IService {
392401

393402
/**
394403
* Finds an embed instance by the name or unique ID that is provided.
395-
*
404+
*
396405
* @param {string} uniqueId
397406
* @returns {(Report | Tile)}
398407
*/
@@ -411,7 +420,7 @@ export class Service implements IService {
411420

412421
/**
413422
* Given an HTML element that has a component embedded within it, removes the component from the list of embedded components, removes the association between the element and the component, and removes the iframe.
414-
*
423+
*
415424
* @param {HTMLElement} element
416425
* @returns {void}
417426
*/
@@ -441,9 +450,9 @@ export class Service implements IService {
441450

442451
/**
443452
* handles tile events
444-
*
445-
* @param {IEvent<any>} event
446-
*/
453+
*
454+
* @param {IEvent<any>} event
455+
*/
447456
handleTileEvents (event: IEvent<any>): void {
448457
if (event.type === 'tile'){
449458
this.handleEvent(event);
@@ -452,7 +461,7 @@ export class Service implements IService {
452461

453462
/**
454463
* Given an event object, finds the embed component with the matching type and ID, and invokes its handleEvent method with the event object.
455-
*
464+
*
456465
* @private
457466
* @param {IEvent<any>} event
458467
*/
@@ -480,7 +489,7 @@ export class Service implements IService {
480489
/**
481490
* API for warm starting powerbi embedded endpoints.
482491
* Use this API to preload Power BI Embedded in the background.
483-
*
492+
*
484493
* @public
485494
* @param {embed.IEmbedConfigurationBase} [config={}]
486495
* @param {HTMLElement} [element=undefined]

test/test.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ function ValidateDashboardConfigurationWorksAsExpected(pageView: string, excepti
3737
pageView: pageView
3838
};
3939

40-
powerbi.embed(component[0], <any>dashboardEmbedConfig);
41-
4240
var exceptionThrown = false;
4341
// Act
4442
try {

0 commit comments

Comments
 (0)