import { ProcessorSubscription } from '../interfaces/ProcessorSubscription'; import { OptionsProcessor } from '../interfaces/Processors'; export class OptionProcessorsStore { private optionsProcessorsByObjectPath: Record[]> = {}; public addProcessor( optionPath: string, processor: OptionsProcessor ): ProcessorSubscription { if (!this.optionsProcessorsByObjectPath[optionPath]) this.optionsProcessorsByObjectPath[optionPath] = []; this.optionsProcessorsByObjectPath[optionPath].push(processor); return { remove: () => this.removeProcessor(optionPath, processor) }; } public getProcessors(optionPath: string) { return this.optionsProcessorsByObjectPath[optionPath]; } private removeProcessor(optionPath: string, processor: OptionsProcessor) { this.optionsProcessorsByObjectPath[optionPath].splice( this.optionsProcessorsByObjectPath[optionPath].indexOf(processor) ); } }