MIGRATE to use qs since that's what we use in many other places

This commit is contained in:
Norbert de Langen 2020-07-03 13:36:21 +02:00
parent 5854b575bd
commit 6d2fa3aa64
No known key found for this signature in database
GPG Key ID: 976651DA156C2825
2 changed files with 5 additions and 11 deletions

View File

@ -33,6 +33,7 @@
"@storybook/core-events": "6.0.0-beta.39", "@storybook/core-events": "6.0.0-beta.39",
"core-js": "^3.0.1", "core-js": "^3.0.1",
"global": "^4.3.2", "global": "^4.3.2",
"qs": "^6.6.0",
"telejson": "^4.0.0" "telejson": "^4.0.0"
}, },
"publishConfig": { "publishConfig": {

View File

@ -3,6 +3,7 @@ import * as EVENTS from '@storybook/core-events';
import Channel, { ChannelEvent, ChannelHandler } from '@storybook/channels'; import Channel, { ChannelEvent, ChannelHandler } from '@storybook/channels';
import { logger, pretty } from '@storybook/client-logger'; import { logger, pretty } from '@storybook/client-logger';
import { isJSON, parse, stringify } from 'telejson'; import { isJSON, parse, stringify } from 'telejson';
import qs from 'qs';
interface Config { interface Config {
page: 'manager' | 'preview'; page: 'manager' | 'preview';
@ -14,16 +15,6 @@ interface BufferedEvent {
reject: (reason?: any) => void; reject: (reason?: any) => void;
} }
const getQueryObject = (): Record<string, string & { refId?: string }> => {
return (window.document.location.search as string)
.substr(1)
.split('&')
.reduce((acc, s) => {
const [k, v] = s.split('=');
return Object.assign(acc, { [k]: v || true });
}, {});
};
export const KEY = 'storybook-channel'; export const KEY = 'storybook-channel';
// TODO: we should export a method for opening child windows here and keep track of em. // TODO: we should export a method for opening child windows here and keep track of em.
@ -81,11 +72,13 @@ export class PostmsgTransport {
const frames = this.getFrames(target); const frames = this.getFrames(target);
const query = qs.parse(location.search, { ignoreQueryPrefix: true });
const data = stringify( const data = stringify(
{ {
key: KEY, key: KEY,
event, event,
refId: getQueryObject().refId, refId: query.refId,
}, },
{ maxDepth: depth, allowFunction } { maxDepth: depth, allowFunction }
); );