Skip to content

Commit

Permalink
vega modifier: rerender on isVisible; populateData actually returns a…
Browse files Browse the repository at this point in the history
… promise that we can await on now
  • Loading branch information
JamesWilmot committed Sep 24, 2022
1 parent 4ff28fe commit 617e147
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions addon/modifiers/vega.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Modifier, { ArgsFor, PositionalArgs, NamedArgs } from 'ember-modifier';
import { registerDestructor } from '@ember/destroyable';
import { next } from '@ember/runloop';

import { isEmpty } from 'lodash';

Expand Down Expand Up @@ -58,6 +59,12 @@ export default class VegaModifier extends Modifier<VegaModifierArgs> {
// Update data only
// TODO: Handle changes to config
await this._populateData(data);
if (isVisible) {
next(() => {
// TODO this is gross and i hate it
window.dispatchEvent(new Event('resize'));
});
}
}
}

Expand Down Expand Up @@ -100,13 +107,13 @@ export default class VegaModifier extends Modifier<VegaModifierArgs> {
window.dispatchEvent(new Event('resize'));
}

private async _populateData(
private _populateData(
data: Record<string, Record<string, number | null>>,
): Promise<void> {
): Promise<Vega.View> {
for (const name of Object.keys(data)) {
this._vegaView.data(name, data[name]);
}

await this._vegaView.runAsync();
return this._vegaView.runAsync();
}
}

0 comments on commit 617e147

Please sign in to comment.