Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(analyzer): move decision for the renderer in to the analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Kuechler authored and lkuechler committed Mar 14, 2018
1 parent 37b778f commit 1442f51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/component/preview.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/styleguide-analyzer/styleguide-analyzer.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1442f51

Please sign in to comment.