|
| 1 | +import { IPlugin } from '../../interfaces/IPlugin'; |
| 2 | +import { PluginStore } from '../../PluginStore'; |
| 3 | +import { Renderer } from './components/Renderer'; |
| 4 | + |
| 5 | +export class RendererPlugin implements IPlugin { |
| 6 | + public pluginStore: PluginStore = new PluginStore(); |
| 7 | + private componentMap: Map<string, Array<any>> = new Map<string, Array<any>>(); |
| 8 | + |
| 9 | + init(pluginStore: PluginStore) { |
| 10 | + this.pluginStore = pluginStore; |
| 11 | + } |
| 12 | + |
| 13 | + addToComponentMap(position: string, component: React.Component) { |
| 14 | + let array = this.componentMap.get(position); |
| 15 | + if (!array) { |
| 16 | + array = [component]; |
| 17 | + } |
| 18 | + this.componentMap.set(position, array); |
| 19 | + } |
| 20 | + |
| 21 | + getRendererComponent() { |
| 22 | + return Renderer; |
| 23 | + } |
| 24 | + |
| 25 | + getComponentsInPosition(position: string) { |
| 26 | + let componentArray = this.componentMap.get(position); |
| 27 | + if (!componentArray) return []; |
| 28 | + |
| 29 | + return componentArray; |
| 30 | + } |
| 31 | + |
| 32 | + activate() { |
| 33 | + this.pluginStore.addFunction( |
| 34 | + 'RendererPlugin.add', |
| 35 | + this.addToComponentMap.bind(this) |
| 36 | + ); |
| 37 | + |
| 38 | + this.pluginStore.addFunction( |
| 39 | + 'RendererPlugin.getComponentsInPosition', |
| 40 | + this.getComponentsInPosition.bind(this) |
| 41 | + ); |
| 42 | + |
| 43 | + this.pluginStore.addFunction( |
| 44 | + 'RendererPlugin.getRendererComponent', |
| 45 | + this.getRendererComponent.bind(this) |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + deactivate() { |
| 50 | + // |
| 51 | + } |
| 52 | +} |
0 commit comments