FIX channel emit failing because it's missing this && ADD roundtrip to correct story && CHANGE roundtrip to useChannel

This commit is contained in:
Norbert de Langen 2019-07-02 11:33:28 +02:00
parent f7fb7e5c1f
commit 7955e4d5c1
6 changed files with 21 additions and 26 deletions

View File

@ -26,6 +26,7 @@
"dependencies": {
"@storybook/addons": "5.2.0-alpha.34",
"@storybook/api": "5.2.0-alpha.34",
"@storybook/client-api": "5.2.0-alpha.34",
"@storybook/client-logger": "5.2.0-alpha.34",
"@storybook/components": "5.2.0-alpha.34",
"@storybook/core-events": "5.2.0-alpha.34",

View File

@ -1,25 +1,11 @@
import { addons } from '@storybook/addons';
import { useChannel } from '@storybook/client-api';
import { EVENTS } from './constants';
const run = async () => {
const channel = await addons.ready();
channel.on(EVENTS.REQUEST, () => {
// do something in the preview context
// then report back to the manager
channel.emit(EVENTS.RESULT, ['from the preview']);
export const withRoundtrip = (storyFn: () => any) => {
const emit = useChannel({
[EVENTS.REQUEST]: () => {
emit(EVENTS.RESULT, ['from the preview']);
},
});
return storyFn();
};
run();
// import { useChannel } from '@storybook/client-api';
// export const myDecorator = () => {
// const emit = useChannel({
// [EVENTS.REQUEST]: () => {
// emit(EVENTS.RESULT, ['from the preview'])}
// });
// };

View File

@ -2,8 +2,10 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { withDecorator } from '@storybook/addon-decorator';
import { withRoundtrip } from '@storybook/addon-roundtrip';
storiesOf('addons|decorator', module)
.addDecorator(withRoundtrip)
.addDecorator(withDecorator())
.add('with decorator', () => (
<div>This story is wrapped with a decorator that is aware of when a story updates/changes</div>

View File

@ -1,8 +1,6 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import '@storybook/addon-roundtrip';
storiesOf('root|group/component', module).add('variant 1', () => <div>This is variant 1</div>);
storiesOf('addons|parameter', module)

View File

@ -287,7 +287,7 @@ export function useChannel(eventMap: EventMap) {
};
}, Object.keys(eventMap));
return channel.emit;
return channel.emit.bind(channel);
}
export function useParameter<S>(parameterKey: string, defaultValue?: S): S | undefined {

View File

@ -14,9 +14,17 @@ import Provider from './provider';
ThemeProvider.displayName = 'ThemeProvider';
HelmetProvider.displayName = 'HelmetProvider';
const getDocsMode = () => {
try {
// eslint-disable-next-line no-undef
return !!DOCS_MODE; // webpack-injected
} catch (e) {
return false;
}
};
const Container = process.env.XSTORYBOOK_EXAMPLE_APP ? React.StrictMode : React.Fragment;
// eslint-disable-next-line no-undef
const docsMode = !!DOCS_MODE; // webpack-injected
const docsMode = getDocsMode();
const Root = ({ provider }) => (
<Container key="container">