Skip to content

Commit

Permalink
fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed May 16, 2022
1 parent eaa2802 commit 6244ef9
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { useEffect } from 'react';
import type { Subscription } from 'rxjs';
import type { EventEmitter } from 'events';
import type { DataView } from '@kbn/data-views-plugin/common';
import type {
Expand All @@ -28,6 +29,8 @@ export const useDataViewUpdates = (
visInstance: VisualizeEditorVisInstance | undefined
) => {
useEffect(() => {
let stateUpdatesSubscription: Subscription;

if (appState && visInstance) {
const syncDataView = async ({ dataView }: VisualizeAppState, setDirty = true) => {
if (
Expand All @@ -45,12 +48,10 @@ export const useDataViewUpdates = (
};

syncDataView(appState.getState(), false);

const stateUpdatesSubscription = appState.state$.subscribe(syncDataView);

return () => {
stateUpdatesSubscription.unsubscribe();
};
stateUpdatesSubscription = appState.state$.subscribe(syncDataView);
}
return () => {
stateUpdatesSubscription?.unsubscribe();
};
}, [appState, eventEmitter, services.dataViews, visInstance]);
};

0 comments on commit 6244ef9

Please sign in to comment.