import { Subject } from 'rxjs' ; import { HttpSetup } from '../http' ; import { InjectedMetadataSetup } from '../injected_metadata' ; import { UiSettingsApi } from './ui_settings_api' ; import { UiSettingsClient } from './ui_settings_client' ; import { IUiSettingsClient } from './types' ; interface UiSettingsServiceDeps { http : HttpSetup ; injectedMetadata : InjectedMetadataSetup ; } internal export class UiSettingsService { private uiSettingsApi ? : UiSettingsApi ; private uiSettingsClient ? : UiSettingsClient ; private done$ = new Subject ( ) ; public setup ( { http , injectedMetadata } ) { this . uiSettingsApi = new UiSettingsApi ( http ) ; http . addLoadingCountSource ( this . uiSettingsApi . getLoadingCount$ ( ) ) ; const legacyMetadata = injectedMetadata . getLegacyMetadata ( ) ; this . uiSettingsClient = new UiSettingsClient ( { api : this . uiSettingsApi , defaults : legacyMetadata . uiSettings . defaults , initialSettings : legacyMetadata . uiSettings . user , done$ : this . done$ , } ) ; return this . uiSettingsClient ; } public start ( ) { return this . uiSettingsClient ! ; } public stop ( ) { this . done$ . complete ( ) ; if ( this . uiSettingsApi ) { this . uiSettingsApi . stop ( ) ; } } }