diff --git a/src/component/preview.ts b/src/component/preview.ts index 9c5ff8988..dd919c8a9 100644 --- a/src/component/preview.ts +++ b/src/component/preview.ts @@ -1,7 +1,5 @@ import { ipcRenderer } from 'electron'; import { JsonObject } from '../store/json'; -import { PatternType } from '../store/styleguide/pattern-type'; -import { renderReact } from './presentation/react/render'; import * as SmoothscrollPolyfill from 'smoothscroll-polyfill'; import { Store } from '../store/store'; @@ -80,14 +78,7 @@ window.onload = () => { return; } - switch (analyzer.getPatternType()) { - case PatternType.React: - renderReact(store, highlightElement); - break; - - default: - console.log('No matching renderer found'); - } + analyzer.render(store, highlightElement); }; // Disable drag and drop from outside the application diff --git a/src/styleguide-analyzer/styleguide-analyzer.ts b/src/styleguide-analyzer/styleguide-analyzer.ts index 7c1ef3d73..b9d674fa5 100644 --- a/src/styleguide-analyzer/styleguide-analyzer.ts +++ b/src/styleguide-analyzer/styleguide-analyzer.ts @@ -1,4 +1,6 @@ import { PatternType } from '../store/styleguide/pattern-type'; +import { HighlightElementFunction } from '../component/preview'; +import { Store } from '../store/store'; import { Styleguide } from '../store/styleguide/styleguide'; /** @@ -19,4 +21,11 @@ export abstract class StyleguideAnalyzer { * @return The pattern type this analyzer creates. */ public abstract getPatternType(): PatternType; + + /** + * Renders the preview application based on the store. + * @param store The store that the render should be based on. + * @param highlightElement The function that should be called inside the renderer when a element need to be highlighted. + */ + public abstract render(store: Store, highlightElement: HighlightElementFunction): void; } diff --git a/src/styleguide-analyzer/typescript-react-analyzer/typescript-react-analyzer.ts b/src/styleguide-analyzer/typescript-react-analyzer/typescript-react-analyzer.ts index 2cc2fe106..12c3d75f1 100644 --- a/src/styleguide-analyzer/typescript-react-analyzer/typescript-react-analyzer.ts +++ b/src/styleguide-analyzer/typescript-react-analyzer/typescript-react-analyzer.ts @@ -5,9 +5,12 @@ import * as FileUtils from 'fs'; import * as PathUtils from 'path'; import { Pattern } from '../../store/styleguide/pattern'; import { PatternType } from '../../store/styleguide/pattern-type'; +import { HighlightElementFunction } from '../../component/preview'; import { Property } from '../../store/styleguide/property/property'; import { PropertyAnalyzer } from './property-analyzer'; import { ReactUtils } from '../typescript/react-utils'; +import { renderReact } from '../../component/presentation/react/render'; +import { Store } from '../../store/store'; import { Styleguide } from '../../store/styleguide/styleguide'; import { StyleguideAnalyzer } from '../styleguide-analyzer'; import { Type } from '../typescript/type'; @@ -204,4 +207,11 @@ export class TypescriptReactAnalyzer extends StyleguideAnalyzer { public getPatternType(): PatternType { return PatternType.React; } + + /** + * @inheritdoc + */ + public render(store: Store, highlightElement: HighlightElementFunction): void { + renderReact(store, highlightElement); + } }