Skip to content

Commit

Permalink
fix: fix createView without container
Browse files Browse the repository at this point in the history
createView was initially called twice, once without having the container initialized. This has been
fixed now.
  • Loading branch information
Alex Bäuerle committed Apr 29, 2021
1 parent 3367cd2 commit 42fe240
Showing 1 changed file with 47 additions and 51 deletions.
98 changes: 47 additions & 51 deletions packages/svelte-vega/src/VegaEmbed.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,72 +35,69 @@
}
$: {
// only create a new view if neccessary
if (!shallowEqual(options, prevOptions, WIDTH_HEIGHT)) {
createView();
} else {
const specChanges = computeSpecChanges(
combineSpecWithDimension(spec, options),
combineSpecWithDimension(prevSpec, prevOptions)
);
const newSignalListeners = signalListeners;
const oldSignalListeners = prevSignalListeners;
if (chartContainer !== undefined) {
// only create a new view if neccessary
if (!shallowEqual(options, prevOptions, WIDTH_HEIGHT)) {
createView();
} else {
const specChanges = computeSpecChanges(
combineSpecWithDimension(spec, options),
combineSpecWithDimension(prevSpec, prevOptions)
);
const newSignalListeners = signalListeners;
const oldSignalListeners = prevSignalListeners;
if (specChanges) {
if (specChanges.isExpensive) {
createView();
} else if (result !== undefined) {
const areSignalListenersChanged = !shallowEqual(
newSignalListeners,
oldSignalListeners
);
const { view } = result;
if (specChanges.width !== false) {
view.width(specChanges.width);
}
if (specChanges.height !== false) {
view.height(specChanges.height);
}
if (areSignalListenersChanged) {
if (oldSignalListeners) {
removeSignalListenersFromView(view, oldSignalListeners);
if (specChanges) {
if (specChanges.isExpensive) {
createView();
} else if (result !== undefined) {
const areSignalListenersChanged = !shallowEqual(
newSignalListeners,
oldSignalListeners
);
const { view } = result;
if (specChanges.width !== false) {
view.width(specChanges.width);
}
if (specChanges.height !== false) {
view.height(specChanges.height);
}
if (newSignalListeners) {
addSignalListenersToView(view, newSignalListeners);
if (areSignalListenersChanged) {
if (oldSignalListeners) {
removeSignalListenersFromView(view, oldSignalListeners);
}
if (newSignalListeners) {
addSignalListenersToView(view, newSignalListeners);
}
}
view.runAsync();
}
} else if (
!shallowEqual(newSignalListeners, oldSignalListeners) &&
result !== undefined
) {
const { view } = result;
if (oldSignalListeners) {
removeSignalListenersFromView(view, oldSignalListeners);
}
if (newSignalListeners) {
addSignalListenersToView(view, newSignalListeners);
}
view.runAsync();
}
} else if (
!shallowEqual(newSignalListeners, oldSignalListeners) &&
result !== undefined
) {
const { view } = result;
if (oldSignalListeners) {
removeSignalListenersFromView(view, oldSignalListeners);
}
if (newSignalListeners) {
addSignalListenersToView(view, newSignalListeners);
}
view.runAsync();
}
prevOptions = options;
prevSignalListeners = signalListeners;
prevSpec = spec;
}
prevOptions = options;
prevSignalListeners = signalListeners;
prevSpec = spec;
}
onMount(async () => {
await createView();
});
onDestroy(() => {
clearView();
});
async function createView() {
clearView();
try {
console.info("Creating new view");
result = await vegaEmbed(chartContainer, spec, options);
Expand All @@ -109,7 +106,6 @@
view.runAsync();
}
onNewView(view);
return view;
} catch (e) {
handleError(e);
}
Expand Down

0 comments on commit 42fe240

Please sign in to comment.