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

Commit

Permalink
refactor(store): make PatternType an enum again
Browse files Browse the repository at this point in the history
  • Loading branch information
faselbaum committed Mar 12, 2018
1 parent 0185fe9 commit 7f9035e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/component/container/pattern-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class PatternListContainer extends React.Component<PatternListContainerPr
for (const pattern of folder.getPatterns()) {
// a synthetic pattern can not have a icon
const icon =
pattern.getType() === PatternType.SYNTHETIC ? undefined : pattern.getIconPath();
pattern.getType() === PatternType.Synthetic ? undefined : pattern.getIconPath();

containerItem.items.push({
name: pattern.getName(),
Expand Down
10 changes: 5 additions & 5 deletions src/component/presentation/react/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { action, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { Page } from '../../../store/page/page';
import { PageElement } from '../../../store/page/page-element';
import { PatternType } from '../../../store/styleguide/pattern-type';
import { PropertyValue } from '../../../store/page/property-value';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Store } from '../../../store/store';

import { HighlightAreaProps, HighlightElementFunction } from '../../preview';
Expand Down Expand Up @@ -142,9 +142,9 @@ class Preview extends React.Component<PreviewProps> {
}

const patternId: string = pattern.getId();
const patternType: string = pattern.getType();
const patternType: PatternType = pattern.getType();

if (patternType === 'synthetic') {
if (patternType === PatternType.Synthetic) {
switch (patternId) {
case 'text':
return pageElement.getPropertyValue('text');
Expand Down
5 changes: 3 additions & 2 deletions src/component/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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,12 +81,12 @@ window.onload = () => {
}

switch (analyzer.getPatternType()) {
case 'react':
case PatternType.React:
renderReact(store, highlightElement);
break;

default:
console.log('No matching rederer found');
console.log('No matching renderer found');
}
};

Expand Down
10 changes: 4 additions & 6 deletions src/store/styleguide/pattern-type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const patternType: { [name: string]: string } = {
SYNTHETIC: 'synthetic',
REACT: 'react'
};

export { patternType as PatternType };
export enum PatternType {
Synthetic = 'synthetic',
React = 'react'
}
7 changes: 4 additions & 3 deletions src/store/styleguide/pattern.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PatternFolder } from './folder';
import { PatternType } from './pattern-type';
import { Property } from './property/property';
import { Store } from '../store';

Expand Down Expand Up @@ -54,7 +55,7 @@ export class Pattern {
/**
* The type of the pattern (e.g. react, angular, vue).
*/
protected type: string;
protected type: PatternType;

/**
* Creates a new pattern.
Expand All @@ -70,7 +71,7 @@ export class Pattern {
public constructor(
id: string,
name: string,
type: string,
type: PatternType,
implementationPath: string,
exportName?: string
) {
Expand Down Expand Up @@ -165,7 +166,7 @@ export class Pattern {
* Returns the type of the pattern (e.g. react, angular, vue).
* @return The type of the pattern (e.g. react, angular, vue).
*/
public getType(): string {
public getType(): PatternType {
return this.type;
}

Expand Down
7 changes: 7 additions & 0 deletions src/styleguide-analyzer/styleguide-analyzer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PatternType } from '../store/styleguide/pattern-type';
import { Styleguide } from '../store/styleguide/styleguide';

/**
Expand All @@ -12,4 +13,10 @@ export abstract class StyleguideAnalyzer {
* @param styleGuide The styleguide to analyze its implementations.
*/
public abstract analyze(styleGuide: Styleguide): void;

/**
* Returns the pattern type this analyzer creates.
* @return The pattern type this analyzer creates.
*/
public abstract getPatternType(): PatternType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class TypescriptReactAnalyzer extends StyleguideAnalyzer {
const pattern = new Pattern(
id,
name,
PatternType.REACT,
PatternType.React,
patternInfo.implementationPath,
exportInfo.name
);
Expand Down Expand Up @@ -197,4 +197,11 @@ export class TypescriptReactAnalyzer extends StyleguideAnalyzer {
const directoryName = PathUtils.basename(fileInfo.directory);
return exportInfo.name || (baseName !== 'index' ? baseName : directoryName);
}

/**
* @inheritdoc
*/
public getPatternType(): PatternType {
return PatternType.React;
}
}

0 comments on commit 7f9035e

Please sign in to comment.