Adds requiresComponentDeclaration option

This commit is contained in:
Max Sagan 2019-03-29 11:08:55 +11:00
parent a27a523c7a
commit 24b98d9fc4
5 changed files with 40 additions and 6 deletions

View File

@ -34,9 +34,24 @@ const createComponentFromTemplate = (template: string) => {
}; };
export const initModuleData = (storyObj: NgStory): any => { export const initModuleData = (storyObj: NgStory): any => {
const { component, template, props, moduleMetadata = {} } = storyObj; const {
component,
template,
props,
moduleMetadata = {},
requiresComponentDeclaration: componentRequiresDeclaration = true,
} = storyObj;
const AnnotatedComponent = template ? createComponentFromTemplate(template) : component; const isCreatingComponentFromTemplate = Boolean(template);
const AnnotatedComponent = isCreatingComponentFromTemplate
? createComponentFromTemplate(template)
: component;
const componentDeclarations =
isCreatingComponentFromTemplate || componentRequiresDeclaration
? [AppComponent, AnnotatedComponent]
: [AppComponent];
const story = { const story = {
component: AnnotatedComponent, component: AnnotatedComponent,
@ -44,7 +59,7 @@ export const initModuleData = (storyObj: NgStory): any => {
}; };
const moduleMeta = getModuleMeta( const moduleMeta = getModuleMeta(
[AppComponent, AnnotatedComponent], componentDeclarations,
[AnnotatedComponent], [AnnotatedComponent],
[AppComponent], [AppComponent],
story, story,

View File

@ -12,6 +12,7 @@ export interface ICollection {
export interface NgStory { export interface NgStory {
component?: any; component?: any;
requiresComponentDeclaration?: boolean;
props: ICollection; props: ICollection;
propsMeta?: ICollection; propsMeta?: ICollection;
moduleMetadata?: NgModuleMetadata; moduleMetadata?: NgModuleMetadata;

View File

@ -22,6 +22,7 @@ export interface IStory {
props?: ICollection; props?: ICollection;
moduleMetadata?: Partial<NgModuleMetadata>; moduleMetadata?: Partial<NgModuleMetadata>;
component?: any; component?: any;
requiresComponentDeclaration?: boolean;
template?: string; template?: string;
} }

View File

@ -47,9 +47,25 @@ const createComponentFromTemplate = (template: string, styles: string[]) => {
const initModule = (storyFn: IStoryFn) => { const initModule = (storyFn: IStoryFn) => {
const storyObj = storyFn(); const storyObj = storyFn();
const { component, template, props, styles, moduleMetadata = {} } = storyObj; const {
component,
template,
props,
styles,
moduleMetadata = {},
requiresComponentDeclaration: componentRequiresDeclaration = true,
} = storyObj;
let AnnotatedComponent = template ? createComponentFromTemplate(template, styles) : component; const isCreatingComponentFromTemplate = Boolean(template);
const AnnotatedComponent = isCreatingComponentFromTemplate
? createComponentFromTemplate(template, styles)
: component;
const componentDeclarations =
isCreatingComponentFromTemplate || componentRequiresDeclaration
? [AppComponent, AnnotatedComponent]
: [AppComponent];
const story = { const story = {
component: AnnotatedComponent, component: AnnotatedComponent,
@ -57,7 +73,7 @@ const initModule = (storyFn: IStoryFn) => {
}; };
return getModule( return getModule(
[AppComponent, AnnotatedComponent], componentDeclarations,
[AnnotatedComponent], [AnnotatedComponent],
[AppComponent], [AppComponent],
story, story,

View File

@ -12,6 +12,7 @@ export interface ICollection {
export interface NgStory { export interface NgStory {
component?: any; component?: any;
requiresComponentDeclaration?: boolean;
props: ICollection; props: ICollection;
propsMeta?: ICollection; propsMeta?: ICollection;
moduleMetadata?: NgModuleMetadata; moduleMetadata?: NgModuleMetadata;