Skip to content

Commit

Permalink
Implemented async data loading/rendering for NPS question
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Jun 21, 2024
1 parent 93d3b47 commit a5dbdb0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/nps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class NpsAdapter {
return this._npsVizualizer;
}

public create(element: HTMLElement): any {
const data = this.model.getCalculatedValues();
this._npsVizualizer = new NpsVizualizerWidget(this.model, data);
public async create(element: HTMLElement) {
const data = await this.model.getCalculatedValues();
this._npsVizualizer = new NpsVizualizerWidget(this.model, data as any);
this._npsVizualizer.render(element);
return this._npsVizualizer;
}
Expand All @@ -69,6 +69,7 @@ export class NpsAdapter {
this._npsVizualizer = undefined;
}
}

export class NpsVizualizer extends VisualizerBase {
private _npsAdapter: NpsAdapter;

Expand All @@ -82,7 +83,7 @@ export class NpsVizualizer extends VisualizerBase {
this._npsAdapter = new NpsAdapter(this);
}

public getCalculatedValues(): any {
protected getCalculatedValuesCore(): any {
let result = {
detractors: 0,
passive: 0,
Expand Down Expand Up @@ -113,9 +114,13 @@ export class NpsVizualizer extends VisualizerBase {
super.destroyContent(container);
}

protected renderContent(container: HTMLElement) {
this._npsAdapter.create(container);
this.afterRender(this.contentContainer);
protected async renderContentAsync(container: HTMLElement) {
const npsNode: HTMLElement = DocumentHelper.createElement("div");
container.appendChild(npsNode);
await this._npsAdapter.create(npsNode);
container.innerHTML = "";
container.appendChild(npsNode);
return container;
}

destroy() {
Expand Down

0 comments on commit a5dbdb0

Please sign in to comment.