Skip to content

Commit

Permalink
fix: components selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 25, 2020
1 parent c6b78bc commit 9a9c85a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/store/src/hooks/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {

import { useStore } from './store';
import { useStory } from './story';
import { useCurrentDocument } from './document';

export interface ComponentInputProps {
/**
Expand All @@ -31,10 +30,12 @@ export const useComponents = ({
const story = useStory({ id: name });
const { component: storyComponentName } = story || {};
const storyComponent = getComponentName(storyComponentName);
const component = storyComponent
? store.components[storyComponent]
: undefined;
const doc = story && story.doc ? store.docs[story.doc] : undefined;
const component =
storyComponent && doc && doc.componentsLookup
? store.components[doc.componentsLookup[storyComponent]]
: undefined;

let components: StoryComponents | undefined = undefined;
const getComponents = (
components: { [key: string]: any } | undefined,
Expand Down Expand Up @@ -103,14 +104,16 @@ export const useComponent = ({
name,
}: ComponentInputProps): StoryComponent | undefined => {
const story = useStory({ id: name });
const doc = useCurrentDocument();
const store = useStore();
const doc = story && story.doc ? store.docs[story.doc] : undefined;
let component;
if (of === CURRENT_STORY) {
component = story ? story.component : doc?.component;
} else {
component = of;
}
const omponentName = getComponentName(component);
return omponentName ? store.components[omponentName] : undefined;
const componentName = getComponentName(component);
return componentName && doc && doc.componentsLookup
? store.components[doc.componentsLookup[componentName]]
: undefined;
};

0 comments on commit 9a9c85a

Please sign in to comment.