Skip to content

Commit

Permalink
Merge pull request #1515 from storybooks/addon-channel-warning
Browse files Browse the repository at this point in the history
Addon channel warning
  • Loading branch information
ndelangen committed Aug 18, 2017
2 parents afeebe0 + 983dd74 commit 45ec15e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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 @@ -55,7 +55,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 || parse(NativeModules.SourceCode.scriptURL).hostname;
const port = params.port !== false ? `:${params.port || 7007}` : '';
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

0 comments on commit 45ec15e

Please sign in to comment.