Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the warning given when using channel before it's defined #1515

Merged
merged 4 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/react-native/src/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ export default class Preview {
getStorybookUI(params = {}) {
return () => {
let webUrl = null;
let channel = addons.getChannel();
let channel = null;

try {
channel = addons.getChannel();
} catch (e) {
// getChannel throws if the channel is not defined,
// which is fine in this case (we will define it below)
}

if (params.resetStorybook || !channel) {
const host = params.host || 'localhost';

Expand Down
10 changes: 7 additions & 3 deletions lib/addons/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ export class AddonStore {
constructor() {
this.loaders = {};
this.panels = {};
// this.channel should get overwritten by setChannel if package versions are
// correct and AddonStore is a proper singleton. If not, this will be null
// (currently required by @storybook/react-native getStorybookUI)
this.channel = null;
this.preview = null;
this.database = null;
}

getChannel() {
// this.channel should get overwritten by setChannel if package versions are
// correct and AddonStore is a proper singleton. If not, throw.
if (!this.channel) {
throw new Error(
'Accessing nonexistent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel'
);
}
return this.channel;
}

Expand Down