Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { secured } = params;
const websocketType = secured ? 'wss' : 'ws';
const httpType = secured ? 'https' : 'http';
const url = `${websocketType}://${host}${port}/${query}`;
webUrl = `${httpType}://${host}${port}`;
channel = createChannel({
url,
async: onDeviceUI,
onError: () => {
this._setInitialStory(initialSelection, shouldPersistSelection);
},
});
}
addons.setChannel(channel);
this._stories.setChannel(channel);
channel.emit(Events.CHANNEL_CREATED);
}
channel.on(Events.GET_STORIES, () => this._sendSetStories());
channel.on(Events.SET_CURRENT_STORY, d => this._selectStoryEvent(d));
this._sendSetStories();
// eslint-disable-next-line @typescript-eslint/no-this-alias
const preview = this;
addons.loadAddons(this._clientApi);
const appliedTheme = { ...theme, ...params.theme };
channel = this._events;
} else {
const host = params.host || parse(NativeModules.SourceCode.scriptURL).hostname;
const port = params.port !== false ? `:${params.port || 7007}` : '';
const query = params.query || '';
const { secured } = params;
const websocketType = secured ? 'wss' : 'ws';
const httpType = secured ? 'https' : 'http';
const url = `${websocketType}://${host}${port}/${query}`;
webUrl = `${httpType}://${host}${port}`;
channel = createChannel({ url });
}
addons.setChannel(channel);
channel.emit('channelCreated');
}
channel.on('getStories', () => this._sendSetStories());
channel.on('setCurrentStory', d => this._selectStory(d));
this._events.on('setCurrentStory', d => this._selectStory(d));
this._sendSetStories();
this._sendGetCurrentStory();
// finally return the preview component
return params.onDeviceUI ? (
) : (
);
return decorateStory => {
if (cache) {
return cache;
}
let channel = null;
if (isBrowser) {
try {
channel = addons.getChannel();
} catch (e) {
channel = createChannel({ page: 'preview' });
addons.setChannel(channel);
}
}
let storyStore;
let clientApi;
if (typeof window !== 'undefined' && window.__STORYBOOK_CLIENT_API__) {
clientApi = window.__STORYBOOK_CLIENT_API__;
// eslint-disable-next-line no-underscore-dangle
storyStore = clientApi._storyStore;
} else {
storyStore = new StoryStore({ channel });
clientApi = new ClientApi({ storyStore, decorateStory });
}
const { clearDecorators } = clientApi;
const configApi = new ConfigApi({ clearDecorators, storyStore, channel, clientApi });
return {
constructor({ url: domain, options }) {
super();
const { secured, host, port } = options;
const websocketType = secured ? 'wss' : 'ws';
let url = `${websocketType}://${domain}`;
if (options.manualId) {
this.pairedId = uuid();
url += `/pairedId=${this.pairedId}`;
}
const channel = this.channel || createChannel({ url });
addons.setChannel(channel);
channel.emit(Events.CHANNEL_CREATED, {
host,
pairedId: this.pairedId,
port,
secured,
});
this.addons = addons;
this.channel = channel;
this.options = options;
}
constructor() {
super();
const channel = createChannel({ page: 'manager' });
addons.setChannel(channel);
channel.emit(Events.CHANNEL_CREATED);
this.addons = addons;
this.channel = channel;
}
this.channel = undefined;
}
const { secured } = options;
const websocketType = secured ? 'wss' : 'ws';
let url = `${websocketType}://${domain}`;
if (options.manualId) {
const pairedId = uuid().substr(-6);
this.pairedId = pairedId;
url += `/pairedId=${this.pairedId}`;
}
if (!this.channel) {
this.channel = createChannel({ url });
addons.setChannel(this.channel);
}
}
function testStorySnapshots(options: StoryshotsOptions = {}) {
if (typeof describe !== 'function') {
throw new Error('testStorySnapshots is intended only to be used inside jest');
}
addons.setChannel(mockChannel());
const { storybook, framework, renderTree, renderShallowTree } = loadFramework(options);
const {
asyncJest,
suite,
storyNameRegex,
storyKindRegex,
stories2snapsConverter,
testMethod,
integrityOptions,
snapshotSerializers,
} = ensureOptionsDefaults(options);
const testMethodParams = {
renderTree,
renderShallowTree,
stories2snapsConverter,