66 */
77
88import React , { Component , RefObject } from 'react' ;
9- import { debounce } from 'lodash' ;
109import { Subscription } from 'rxjs' ;
11- import { distinctUntilChanged , skip , startWith } from 'rxjs/operators' ;
1210import { v4 as uuidv4 } from 'uuid' ;
1311import { EuiLoadingChart } from '@elastic/eui' ;
1412import { EmbeddableFactory , ViewMode } from '@kbn/embeddable-plugin/public' ;
1513import type { LayerDescriptor } from '../../common/descriptor_types' ;
1614import { INITIAL_LOCATION } from '../../common' ;
17- import { RENDER_TIMEOUT } from '../../common/constants' ;
1815import { MapEmbeddable , MapEmbeddableInput , MapEmbeddableOutput } from '../embeddable' ;
1916import { createBasemapLayerDescriptor } from '../classes/layers/create_basemap_layer_descriptor' ;
2017
@@ -39,7 +36,7 @@ export class PassiveMap extends Component<Props, State> {
3936 private _isMounted = false ;
4037 private _prevPassiveLayer = this . props . passiveLayer ;
4138 private readonly _embeddableRef : RefObject < HTMLDivElement > = React . createRef < HTMLDivElement > ( ) ;
42- private _outputSubscription : Subscription | undefined ;
39+ private _onRenderSubscription : Subscription | undefined ;
4340
4441 state : State = { mapEmbeddable : null } ;
4542
@@ -53,8 +50,8 @@ export class PassiveMap extends Component<Props, State> {
5350 if ( this . state . mapEmbeddable ) {
5451 this . state . mapEmbeddable . destroy ( ) ;
5552 }
56- if ( this . _outputSubscription ) {
57- this . _outputSubscription . unsubscribe ( ) ;
53+ if ( this . _onRenderSubscription ) {
54+ this . _onRenderSubscription . unsubscribe ( ) ;
5855 }
5956 }
6057
@@ -65,14 +62,6 @@ export class PassiveMap extends Component<Props, State> {
6562 }
6663 }
6764
68- _onRenderComplete = debounce ( ( ) => {
69- if ( ! this . _isMounted ) {
70- return ;
71- }
72-
73- this . props . onRenderComplete ( ) ;
74- } , RENDER_TIMEOUT ) ;
75-
7665 async _setupEmbeddable ( ) {
7766 const basemapLayerDescriptor = createBasemapLayerDescriptor ( ) ;
7867 const intialLayers = basemapLayerDescriptor ? [ basemapLayerDescriptor ] : [ ] ;
@@ -101,19 +90,11 @@ export class PassiveMap extends Component<Props, State> {
10190 return ;
10291 }
10392
104- this . _outputSubscription = mapEmbeddable
105- . getOutput$ ( )
106- . pipe (
107- // wrapping distinctUntilChanged with startWith and skip to prime distinctUntilChanged with an initial value.
108- startWith ( mapEmbeddable . getOutput ( ) ) ,
109- distinctUntilChanged ( ( a , b ) => a . loading === b . loading ) ,
110- skip ( 1 )
111- )
112- . subscribe ( ( output ) => {
113- if ( output . loading ) {
114- this . _onRenderComplete . cancel ( ) ;
115- } else {
116- this . _onRenderComplete ( ) ;
93+ this . _onRenderSubscription = mapEmbeddable
94+ . getOnRenderComplete$ ( )
95+ . subscribe ( ( ) => {
96+ if ( this . _isMounted ) {
97+ this . props . onRenderComplete ( ) ;
11798 }
11899 } ) ;
119100
0 commit comments