Skip to content

Commit

Permalink
fix: missing component check
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Aug 29, 2020
1 parent d76dc83 commit deb1653
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions core/store/src/state/context/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@component-controls/core';

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

export interface ComponentInputProps {
Expand Down Expand Up @@ -134,13 +134,14 @@ export const useComponent = ({
*/

export const useCurrentPropsCount = (): number => {
const components = useComponents({ of: '.' });
const store = useStore();
const story = useCurrentStory();
const components = useComponents({ name: story?.id });
const doc = useCurrentDocument();
return components && doc
? Object.keys(components).reduce((acc, key) => {
const component = store.components[doc.componentsLookup[key]];
return acc + Object.keys(component.info?.props || {}).length;
return acc + Object.keys(component?.info?.props || {}).length;
}, 0)
: 0;
};
9 changes: 6 additions & 3 deletions core/store/src/state/recoil/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@component-controls/core';

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

export interface ComponentInputProps {
Expand All @@ -32,7 +32,9 @@ export const useComponents = ({
name,
}: ComponentInputProps): Components => {
const store = useStore();
const story = useStory({ id: name });
const story =
of === CURRENT_STORY ? useCurrentStory() : useStory({ id: name });

const { component: storyComponentName } = story || {};
const storyComponent = getComponentName(storyComponentName);
const doc = story && story.doc ? store.docs[story.doc] : undefined;
Expand Down Expand Up @@ -133,8 +135,9 @@ export const useComponent = ({
*/

export const useCurrentPropsCount = (): number => {
const components = useComponents({ of: '.' });
const store = useStore();
const story = useCurrentStory();
const components = useComponents({ name: story?.id });
const doc = useCurrentDocument();
return components && doc
? Object.keys(components).reduce((acc, key) => {
Expand Down

0 comments on commit deb1653

Please sign in to comment.