import { PluginInitializerContext , CoreSetup , CoreStart , Plugin } from 'src/core/public' ; import { ExpressionsService , ExpressionsServiceSetup , ExpressionsServiceStart , ExecutionContext , } from '../common' ; import { setRenderersRegistry , setNotifications , setExpressionsService } from './services' ; import { ReactExpressionRenderer } from './react_expression_renderer' ; import { ExpressionLoader , loader } from './loader' ; import { render , ExpressionRenderHandler } from './render' ; export type ExpressionsSetup = ExpressionsServiceSetup ; export interface ExpressionsStart extends ExpressionsServiceStart { ExpressionLoader : typeof ExpressionLoader ; ExpressionRenderHandler : typeof ExpressionRenderHandler ; loader : typeof loader ; ReactExpressionRenderer : typeof ReactExpressionRenderer ; render : typeof render ; } export class ExpressionsPublicPlugin implements Plugin < ExpressionsSetup , ExpressionsStart > { private readonly expressions : ExpressionsService = new ExpressionsService ( ) ; constructor ( initializerContext ) { } private configureExecutor ( core ) { const { executor } = this . expressions ; const getSavedObject = async ( type , id ) => { const [ start ] = await core . getStartServices ( ) ; return start . savedObjects . client . get ( type , id ) ; } ; executor . extendContext ( { environment : 'client' , getSavedObject , } ) ; } public setup ( core ) { this . configureExecutor ( core ) ; const { expressions } = this ; const { renderers } = expressions ; setRenderersRegistry ( renderers ) ; setExpressionsService ( expressions ) ; const setup = expressions . setup ( ) ; return Object . freeze ( setup ) ; } public start ( core ) { setNotifications ( core . notifications ) ; const { expressions } = this ; const start = { ... expressions . start ( ) , ExpressionLoader , ExpressionRenderHandler , loader , ReactExpressionRenderer , render , } ; return Object . freeze ( start ) ; } public stop ( ) { this . expressions . stop ( ) ; } }