From 617e147805e8d5b1dfb8f3cbbb8bc8925162a0a6 Mon Sep 17 00:00:00 2001 From: James Wilmot Date: Sat, 24 Sep 2022 17:08:02 +1000 Subject: [PATCH] vega modifier: rerender on isVisible; populateData actually returns a promise that we can await on now --- addon/modifiers/vega.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addon/modifiers/vega.ts b/addon/modifiers/vega.ts index 03ac71b..e2339bb 100644 --- a/addon/modifiers/vega.ts +++ b/addon/modifiers/vega.ts @@ -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'; @@ -58,6 +59,12 @@ export default class VegaModifier extends Modifier { // 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')); + }); + } } } @@ -100,13 +107,13 @@ export default class VegaModifier extends Modifier { window.dispatchEvent(new Event('resize')); } - private async _populateData( + private _populateData( data: Record>, - ): Promise { + ): Promise { for (const name of Object.keys(data)) { this._vegaView.data(name, data[name]); } - await this._vegaView.runAsync(); + return this._vegaView.runAsync(); } }