Skip to content

Commit

Permalink
fix: load stories bundle with render functions
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed May 31, 2020
1 parent 1a86b90 commit 814719d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions core/webpack-compile/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/bundle');
3 changes: 2 additions & 1 deletion core/webpack-compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"files": [
"dist/",
"package.json",
"README.md"
"README.md",
"bundle.js"
],
"scripts": {
"build": "yarn cross-env NODE_ENV=production rollup -c",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { Header } from './Header';
import { PagesConfig } from './types';

interface LayoutProps {
children: React.ReactNode;
title?: string;
storyStore: Store;
storyId: string;
Expand Down
4 changes: 1 addition & 3 deletions integrations/gatsby-theme-stories/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LoaderOptions } from './types';

const defaultPresets = ['react', 'react-docgen-typescript'];

let loadedStore: StoriesStore | undefined;
exports.sourceNodes = async function sourceNodes(
{ actions, createContentDigest, createNodeId }: NodePluginArgs,
options: LoaderOptions,
Expand All @@ -18,7 +17,7 @@ exports.sourceNodes = async function sourceNodes(
presets: defaultPresets,
configPath: options.configPath,
});
loadedStore = loadStoryStore(store);
const loadedStore: StoriesStore | undefined = loadStoryStore(store);

if (loadedStore) {
Object.keys(loadedStore.kinds).forEach(key => {
Expand Down Expand Up @@ -82,7 +81,6 @@ exports.createPages = async ({ graphql, actions }: CreatePagesArgs) => {
context: {
title: node.name,
storyId: node.id,
loadedStore,
},
});
});
Expand Down
12 changes: 5 additions & 7 deletions integrations/gatsby-theme-stories/src/templates/StoryPage.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import React, { FC, useMemo } from 'react';

import { StoriesStore } from '@component-controls/specification';
import { Store } from '@component-controls/store';
import { loadStoryStore, Store } from '@component-controls/store';
import * as bundle from '@component-controls/webpack-compile/bundle';

import { Layout } from '../components/Layout';
import { pages } from '../config/pages';

interface SitePageProps {
pathContext: {
title: string;
loadedStore: StoriesStore;
storyId: string;
};
}

const SitePage: FC<SitePageProps> = ({
pathContext: { title, loadedStore, storyId },
}) => {
const SitePage: FC<SitePageProps> = ({ pathContext: { title, storyId } }) => {
const storyStore = useMemo(
() =>
new Store({
store: loadedStore,
store: loadStoryStore(bundle),
updateLocalStorage: false,
}),
[loadedStore],
[],
);
return (
<Layout
Expand Down

0 comments on commit 814719d

Please sign in to comment.