import { IRegistry } from '../types' ; import { ExpressionRenderer } from './expression_renderer' ; import { AnyExpressionRenderDefinition } from './types' ; export class ExpressionRendererRegistry implements IRegistry < ExpressionRenderer > { private readonly renderers : Map < string , ExpressionRenderer > = new Map < string , ExpressionRenderer > ( ) ; register ( definition ) { if ( typeof definition === 'function' ) definition = definition ( ) ; const renderer = new ExpressionRenderer ( definition ) ; this . renderers . set ( renderer . name , renderer ) ; } public get ( id ) { return this . renderers . get ( id ) || null ; } public toJS ( ) { return this . toArray ( ) . reduce ( ( acc , renderer ) => ( { ... acc , [ renderer . name ] : renderer , } ) , { } as Record < string , ExpressionRenderer > ) ; } public toArray ( ) { return [ ... this . renderers . values ( ) ] ; } }