Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function showException(exception) {
addons.getChannel().emit(Events.STORY_THREW_EXCEPTION, exception);
showErrorDisplay(exception);
// Log the stack to the console. So, user could check the source code.
logger.error(exception.stack);
}
function triggerUpdate() {
const hooks = getHooksContextOrNull();
// Rerun getStory if updates were triggered synchronously, force rerender otherwise
if (hooks != null && hooks.currentPhase !== 'NONE') {
hooks.hasUpdates = true;
} else {
try {
addons.getChannel().emit(FORCE_RE_RENDER);
} catch (e) {
logger.warn('State updates of Storybook preview hooks work only in browser');
}
}
}
storiesOf = (kind, m) => {
if (!kind && typeof kind !== 'string') {
throw new Error('Invalid or missing kind provided for stories, should be a string');
}
if (!m) {
logger.warn(
`Missing 'module' parameter for story with a kind of '${kind}'. It will break your HMR`
);
}
if (m && m.hot && m.hot.dispose) {
m.hot.dispose(() => {
const { _storyStore } = this;
_storyStore.remove();
// TODO: refactor this
// Maybe not needed at all if stories can just be overwriten ?
this._storyStore.removeStoryKind(kind);
this._storyStore.incrementRevision();
});
}
private handleEvent(rawEvent: RawEvent): void {
try {
const { data } = rawEvent;
const { key, event } = typeof data === 'string' && isJSON(data) ? parse(data) : data;
if (key === KEY) {
logger.debug(`message arrived at ${this.config.page}`, event.type, ...event.args);
this.handler(event);
}
} catch (error) {
logger.error(error);
// debugger;
}
}
}
private handleEvent(rawEvent: RawEvent): void {
try {
const { data } = rawEvent;
const { key, event } = typeof data === 'string' && isJSON(data) ? parse(data) : data;
if (key === KEY) {
logger.debug(`message arrived at ${this.config.page}`, event.type, ...event.args);
this.handler(event);
}
} catch (error) {
logger.error(error);
// debugger;
}
}
}
async function init({ api: fullApi }: API) {
const { versions = {} } = store.getState();
const now = Date.now();
if (!lastVersionCheck || now - lastVersionCheck > checkInterval) {
try {
const { latest, next } = await fetchLatestVersion(currentVersion);
await store.setState(
{
versions: { ...versions, latest, next },
lastVersionCheck: now,
},
{ persistence: 'permanent' }
);
} catch (error) {
logger.warn(`Failed to fetch latest version from server: ${error}`);
}
}
if (api.versionUpdateAvailable()) {
const latestVersion = api.getLatestVersion().version;
if (
latestVersion !== dismissedVersionNotification &&
!semver.patch(latestVersion) &&
!semver.prerelease(latestVersion) &&
mode !== 'production'
) {
fullApi.addNotification({
id: 'update',
link: '/settings/about',
content: `🎉 Storybook ${latestVersion} is available!`,
function sendEvent(
context,
source,
locationsMap,
mainFileLocation,
dependencies,
localDependencies,
prefix,
idsToFrameworks
) {
if (!context || !context.id || !context.kind || !context.story) {
logger.warn(
'@storybook/source-loader was applied to a file which does not contain a story. Please check your webpack configuration and make sure to apply @storybook/source-loader only to files containg stories. Related file:'
);
logger.warn(source);
return;
}
const channel = addons.getChannel();
const currentLocation = getLocation(context, locationsMap);
channel.emit(STORY_EVENT_ID, {
edition: {
source,
mainFileLocation,
dependencies,
localDependencies,
prefix,
idsToFrameworks,
},
story: {
api.addDecorator = (decorator: DecoratorFunction) => {
if (hasAdded) {
logger.warn(`You have added a decorator to the kind '${kind}' after a story has already been added.
In Storybook 4 this applied the decorator only to subsequent stories. In Storybook 5+ it applies to all stories.
This is probably not what you intended. Read more here: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md`);
}
localDecorators.push(decorator);
return api;
};
export const ensure = (input: ThemeVars): Theme => {
if (!input) {
return convert(light);
}
const missing = deletedDiff(light, input);
if (Object.keys(missing).length) {
logger.warn(
dedent`
Your theme is missing properties, you should update your theme!
theme-data missing:
`,
missing
);
}
return convert(input);
};
const isColorString = (color: string) => {
if (typeof color !== 'string') {
logger.warn(
`Color passed to theme object should be a string. Instead ` +
`${color}(${typeof color}) was passed.`
);
return false;
}
return true;
};